Struct db_adapter::guild::GuildConfig [−][src]
pub struct GuildConfig(pub GuildId);
Expand description
Wraps around a guilds
row
GuildConfig
provides an API covering every common use-case. When it doesn’t piecing methods
together is simple and safe. As much as possible it tries to issue as little queries as possible
so you can confidently use the methods.
Connection (conn
) parameter.
For the sake of flexibility as little constraints as possible were put on the methods.
The major example of this is the conn
parameter which generally accepts anything that
implements: [sqlx::Executor
]. This means both sqlx::PgPool
and
[sqlx::PgConnection
] can be used. However some methods need to issue multiple queries.
As such it requires a conn
that implements Copy
. In those cases simply pass a &PgPool
Errors
For simplicty’s sake only methods that can give other errors than [sqlx::Error
] have a section
detailing the error.
All methods provided by Self
return a Result
which’s Err
variant is
AdapterError
. One of the later’s variant wraps around [sqlx::Error
] which is returned by
every [sqlx
] method that interacts with the database. These are all about database errors, which for the
user of the library, should only be caused by incorrect setup (see crate
).
Tuple Fields
0: GuildId
Implementations
pub async fn new<'a, 'b, PgExec: Executor<'a, Database = Postgres> + Copy>(
conn: PgExec,
builder: GuildConfigBuilder<'b>
) -> Result<Self, AdapterError>
pub async fn new<'a, 'b, PgExec: Executor<'a, Database = Postgres> + Copy>(
conn: PgExec,
builder: GuildConfigBuilder<'b>
) -> Result<Self, AdapterError>
Adds a new entry to the guilds
table.
Errors
Errors with GuildConfigError::AlreadyExists
if a row with the same id
already exists in the DB
pub async fn exists<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<bool, AdapterError>
pub async fn exists<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<bool, AdapterError>
true
if the guild exists in the database, false
otherwise.
pub async fn get_welcome_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<Option<String>, AdapterError>
pub async fn get_welcome_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<Option<String>, AdapterError>
welcome_message
currently in use
This is the message sent to new users when they join. Disabled if None
.
pub async fn get_goodbye_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<Option<String>, AdapterError>
pub async fn get_goodbye_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<Option<String>, AdapterError>
goodbye_message
currently in use
pub async fn set_welcome_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
msg: Option<&str>
) -> Result<(), AdapterError>
pub async fn set_welcome_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
msg: Option<&str>
) -> Result<(), AdapterError>
Change welcome_message
Error
If the message is over discord’s length limit for a message (2000 characters) the query will not be made
and the method will return GuildConfigError::MessageTooLong
.
pub async fn set_goodbye_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
msg: Option<&str>
) -> Result<(), AdapterError>
pub async fn set_goodbye_message<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
msg: Option<&str>
) -> Result<(), AdapterError>
Change goodbye_message
Error
If the message is over discord’s length limit for a message (2000 characters) the query will not be made
and the method will return GuildConfigError::MessageTooLong
.
pub async fn get_advertise<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<bool, AdapterError>
pub async fn get_advertise<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<bool, AdapterError>
advertise
pub async fn set_advertise<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
policy: bool
) -> Result<(), AdapterError>
pub async fn set_advertise<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
policy: bool
) -> Result<(), AdapterError>
Change the advertisement policy
pub async fn get_admin_chan<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<Option<ChannelId>, AdapterError>
pub async fn get_admin_chan<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec
) -> Result<Option<ChannelId>, AdapterError>
admin_chan
Events demanding the attention of guild admins are posted to the admin channel. This includes but is not limited to slap notices, upcoming updates, etc.
pub async fn set_admin_chan<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
chan: Option<ChannelId>
) -> Result<(), AdapterError>
pub async fn set_admin_chan<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
chan: Option<ChannelId>
) -> Result<(), AdapterError>
Change the admin_chan
pub async fn get_roles_with<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
privilege: Privilege
) -> Result<Vec<RoleId>, AdapterError>
pub async fn get_roles_with<'a, PgExec: Executor<'a, Database = Postgres>>(
&self,
conn: PgExec,
privilege: Privilege
) -> Result<Vec<RoleId>, AdapterError>
Roles with the specified privilege
pub fn grant_privilege<'a, 'life_self, 'async_recursion, PgExec: Executor<'a, Database = Postgres> + Copy>(
&'life_self self,
conn: PgExec,
id: RoleId,
privilege: Privilege
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_recursion>> where
PgExec: 'async_recursion,
'life_self: 'async_recursion,
pub fn grant_privilege<'a, 'life_self, 'async_recursion, PgExec: Executor<'a, Database = Postgres> + Copy>(
&'life_self self,
conn: PgExec,
id: RoleId,
privilege: Privilege
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_recursion>> where
PgExec: 'async_recursion,
'life_self: 'async_recursion,
Gives a role a privilege
pub fn deny_privilege<'a, 'life_self, 'async_recursion, PgExec: Executor<'a, Database = Postgres> + Copy>(
&'life_self self,
conn: PgExec,
id: RoleId,
privilege: Privilege
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_recursion>> where
PgExec: 'async_recursion,
'life_self: 'async_recursion,
pub fn deny_privilege<'a, 'life_self, 'async_recursion, PgExec: Executor<'a, Database = Postgres> + Copy>(
&'life_self self,
conn: PgExec,
id: RoleId,
privilege: Privilege
) -> Pin<Box<dyn Future<Output = Result<(), AdapterError>> + Send + 'async_recursion>> where
PgExec: 'async_recursion,
'life_self: 'async_recursion,
Strips a role from a privilege
pub async fn have_privilege<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
roles: &[RoleId],
privilege: Privilege
) -> Result<bool, AdapterError>
pub async fn have_privilege<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
roles: &[RoleId],
privilege: Privilege
) -> Result<bool, AdapterError>
If all roles have a privilege
pub async fn has_privilege<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
role: RoleId,
privilege: Privilege
) -> Result<bool, AdapterError>
pub async fn has_privilege<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
role: RoleId,
privilege: Privilege
) -> Result<bool, AdapterError>
If a role has a privilege
pub async fn has_privileges<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
role: RoleId,
privileges: &[Privilege]
) -> Result<bool, AdapterError>
pub async fn has_privileges<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
role: RoleId,
privileges: &[Privilege]
) -> Result<bool, AdapterError>
Id a role has all specified privileges
pub async fn get_privileges_for<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
role: RoleId
) -> Result<Vec<Privilege>, AdapterError>
pub async fn get_privileges_for<'a, PgExec: Executor<'a, Database = Postgres> + Copy>(
&self,
conn: PgExec,
role: RoleId
) -> Result<Vec<Privilege>, AdapterError>
All privileges granted to a role
Trait Implementations
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for GuildConfig
impl Send for GuildConfig
impl Sync for GuildConfig
impl Unpin for GuildConfig
impl UnwindSafe for GuildConfig
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more