summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/consts.rs4
-rw-r--r--src/handlers/event/message.rs12
-rw-r--r--src/main.rs32
-rw-r--r--src/settings.rs2
4 files changed, 29 insertions, 21 deletions
diff --git a/src/consts.rs b/src/consts.rs
index afcd499..b108f34 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -1,7 +1,3 @@
-use poise::serenity_prelude::GuildId;
-
-pub const TEAWIE_GUILD: GuildId = GuildId(1055663552679137310);
-
pub const TEAMOJIS: [&str; 15] = [
"<:teawiecry:1056438041872433303>",
"<:teawiederp:1056438043109757018>",
diff --git a/src/handlers/event/message.rs b/src/handlers/event/message.rs
index 0004caf..dab2047 100644
--- a/src/handlers/event/message.rs
+++ b/src/handlers/event/message.rs
@@ -7,23 +7,19 @@ use poise::FrameworkContext;
pub async fn handle(
ctx: &Context,
- framework: FrameworkContext<'_, Data, Report>,
+ _framework: FrameworkContext<'_, Data, Report>,
msg: &Message,
data: &Data,
) -> Result<()> {
- if should_echo(framework, msg, data).await? {
+ if should_echo(ctx, msg, data).await? {
msg.reply(ctx, &msg.content).await?;
}
Ok(())
}
-async fn should_echo(
- _framework: FrameworkContext<'_, Data, Report>,
- msg: &Message,
- data: &Data,
-) -> Result<bool> {
- if msg.author.bot && msg.webhook_id.is_none() {
+async fn should_echo(ctx: &Context, msg: &Message, data: &Data) -> Result<bool> {
+ if (msg.author.bot && msg.webhook_id.is_none()) || msg.is_own(ctx) {
debug!("Not repeating another bot");
return Ok(false);
}
diff --git a/src/main.rs b/src/main.rs
index 6921f8a..afedd1a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ use log::*;
use poise::{
serenity_prelude as serenity, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions,
};
+use redis::AsyncCommands;
use settings::Settings;
mod api;
@@ -68,18 +69,33 @@ async fn main() -> Result<()> {
.options(options)
.setup(|ctx, _ready, framework| {
Box::pin(async move {
+ let data = Data::new()?;
+
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
info!("Registered global commands!");
- poise::builtins::register_in_guild(
- ctx,
- &commands::to_guild_commands(),
- consts::TEAWIE_GUILD,
- )
- .await?;
- info!("Registered guild commands to {}", consts::TEAWIE_GUILD);
+ // register "extra" commands in guilds that allow it
+ let mut con = data.redis.get_async_connection().await?;
+
+ info!("Fetching all guild settings from Redis...this might take a while");
+ let guilds: Vec<String> = con.keys(format!("{}:*", settings::ROOT_KEY)).await?;
+
+ for guild in guilds {
+ let settings: Settings = con.get(guild).await?;
+
+ if settings.optional_commands_enabled {
+ poise::builtins::register_in_guild(
+ ctx,
+ &commands::to_guild_commands(),
+ settings.guild_id,
+ )
+ .await?;
+ info!("Registered guild commands to {}", settings.guild_id);
+ } else {
+ debug!("Not registering guild commands to {} since optional_commands_enabled is False", settings.guild_id);
+ }
+ }
- let data = Data::new()?;
Ok(data)
})
});
diff --git a/src/settings.rs b/src/settings.rs
index 6c02e5c..64cde1f 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -4,7 +4,7 @@ use redis::{AsyncCommands as _, Client};
use redis_macros::{FromRedisValue, ToRedisArgs};
use serde::{Deserialize, Serialize};
-const ROOT_KEY: &str = "settings-v1";
+pub const ROOT_KEY: &str = "settings-v1";
#[derive(poise::ChoiceParameter)]
pub enum SettingsProperties {