[][src]Struct automate::Configuration

pub struct Configuration { /* fields omitted */ }

Allows specifying API token, registering stateful and stateless listeners, stating the shard id, intents and configuring logger.

The resulting object can then be used in Automate::launch or the ShardManager.

Example


let config = Configuration::from_env("DISCORD_API_TOKEN")
       .disable_logging()
       .register(stateless!(kick_spammer));

Implementations

impl Configuration[src]

pub fn new<S: Into<String>>(token: S) -> Configuration[src]

Creates a configuration with the specified API token.

This configuration will by default have logging enabled and outputting all logs with a level higher or equal to LevelFiler::Info

pub fn from_env<S: Into<String>>(env: S) -> Configuration[src]

Creates a configuration by taking the API token from the specified environment variable. The environment variable is retrieved using env::var and thus needs to be specified at runtime and not compile time.

This configuration will by default have logging enabled and outputting all logs with a level higher or equal to LevelFiler::Info

pub fn shard(&mut self, shard_id: u32, total_shards: u32) -> &mut Self[src]

Sets the shard id of this configuration and the total amount of shards.

If using the ShardManager or Automate::launch to launch the bot, you should not use this function since it is done automatically.

pub fn token<S: Into<String>>(self, token: S) -> Self[src]

Sets the API token.

pub fn enable_logging(self) -> Self[src]

Enables logging. Logger is enabled by default.

pub fn disable_logging(self) -> Self[src]

Disables logging.

pub fn level_for<S: Into<String>>(self, module: S, min: LevelFilter) -> Self[src]

Sets the minimum log level for the given module.

By default, automate will be set to LevelFilter::Info and its dependencies won't log anything.

pub fn register(self, listeners: Vec<ListenerType>) -> Self[src]

Registers a listener state or a stateless listener function with the ̀#[listener] attribute.

pub fn add_initializer<F: Fn(&mut StorageContainer) + Send + Sync + 'static>(
    self,
    initializer: F
) -> Self
[src]

Registers a function that initializes a storage by either calling StorageContainer::initialize which accepts an existing storage or StorageContainer::write which creates an empty storage and calls the provided callback function.

pub fn intents(self, intents: u32) -> Self[src]

Intents are a system to help you lower the amount of data you need to process by specifying the events Discord should relay to the library.

An Intents concerns one or more event. By default, intents are not specified thus the bot is subscribed to all events.

When specifying a single [], you must explicitly cast the intent to u32. When specifying multiple intents, you can aggregate them using the bitwise or operator.

Example

The bot in the following example will only receive events about message creation, update and deletion and when a user starts typing in a guild channel:

use automate::{Configuration, Intent::*};

Configuration::from_env("DISCORD_API_TOKEN")
        .intents(GuildMessages | GuildMessageTyping);

If you want to only listen to one intent type, you must explicitly cast the intent to u32 like the following example which only listens to events about guild members:

use automate::{Configuration, Intent::*};

Configuration::from_env("DISCORD_API_TOKEN")
        .intents(GuildMembers as u32);

pub fn member_threshold(self, threshold: u32) -> Self[src]

Number of members where the gateway will stop sending offline members in the guild member list. The value must be between 50 and 250.

If not set, the value will default to 50.

pub fn presence(self, presence: UpdateStatus) -> Self[src]

Sets the presence of the bot.

This can later be modified using the update_status gateway command.

pub fn guild_subscriptions(self, enabled: bool) -> Self[src]

Enables dispatching of guild subscription events (presence and typing events).

Defaults to true.

pub fn collector_period(self, period: u64) -> Self[src]

Sets the bucket collector period in seconds. Defaults to one hour.

A bucket is a structure specifying the state of the rate-limit of a specified endpoint. It contains the amount of remaining API calls for the endpoint and the time at which it will reset.

After each HTTP API call and in order to not reach the rate-limit set by Discord, the library keeps a hashmap associating the routes to their bucket. However, when these buckets reset, it is not necessary to keep them in memory anymore. Keeping buckets as long as the program runs would gradually use more and more memory as the bot joins and leaves guilds and sends DMs to users.

The bucket collector was thus created to clean up memory every period seconds.

For bots that are only in a few guilds and are meant to stay that way, it is not necessary to run the collector often. Once every few days will suffice.

Trait Implementations

impl Clone for Configuration[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,