In the process of adding SM Server commands

main
Joey Pollack 2 years ago
parent 3befd3f001
commit 8fcdcef2cb

@ -1,4 +1,12 @@
use serenity::prelude::*; use serenity::prelude::*;
use serenity::model::prelude::*; use serenity::model::prelude::*;
use serenity::model::channel::Message; use serenity::model::channel::Message;
use crate::utils;
pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId)
{
}

@ -5,17 +5,30 @@ use serenity::model::channel::Message;
// use serenity::model::prelude::*; // use serenity::model::prelude::*;
pub mod test; pub mod test;
pub mod admin;
pub mod sm_server;
use crate::utils; use crate::utils;
pub async fn parse(ctx: Context, msg: Message) pub async fn parse(ctx: Context, msg: Message)
{ {
if let Some(server_id) = msg.guild_id if let Some(server_id) = msg.guild_id
{ {
// This is not a command
if msg.content.len() == 0 || msg.content.chars().nth(0) != Some('.')
{
return;
}
if server_id == utils::ADMIN_SERVER_ID && msg.channel_id == utils::ADMIN_COMMAND_CHANNEL_ID if server_id == utils::ADMIN_SERVER_ID && msg.channel_id == utils::ADMIN_COMMAND_CHANNEL_ID
{ {
test::parse_command(ctx, msg, server_id).await; test::parse_command(ctx, msg, server_id).await;
} }
if server_id == utils::SM_SERVER_ID
{
}
} }
else else
{ {

@ -0,0 +1,36 @@
use serenity::prelude::*;
use serenity::model::prelude::*;
use serenity::model::channel::Message;
use crate::utils;
pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId)
{
if msg.content == ".randomizer"
{
let item = utils::get_random_item();
if let Err(why) = msg.channel_id.say(&ctx.http, format!("You found {}!", item)).await
{
println!("Error sending message: {:?}", why);
}
}
let command_lower = msg.content.to_lowercase();
let mut command_iter = command_lower.split_whitespace();
let command_start = command_iter.next();
if command_start == Some(".color")
{
if let Some(arg) = command_iter.next()
{
match arg
{
// TODO: add color roles
_ => utils::Logger::log_error(ctx, &format!("unknown .color argument: {}", arg)).await
};
}
}
}

@ -46,14 +46,4 @@ pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId)
} }
return; return;
} }
if msg.content == ".randomizer"
{
let item = utils::get_random_item();
if let Err(why) = msg.channel_id.say(&ctx.http, format!("You found {}!", item)).await
{
println!("Error sending message: {:?}", why);
}
}
} }

@ -3,15 +3,24 @@ mod commands;
mod data_loader; mod data_loader;
mod utils; mod utils;
use std::collections::HashSet; // use std::collections::HashSet;
use std::sync::Arc;
use std::sync::atomic::AtomicU64;
use serenity::async_trait; use serenity::async_trait;
use serenity::prelude::*; use serenity::prelude::*;
use serenity::model::prelude::*; // use serenity::model::prelude::*;
use serenity::model::channel::Message; use serenity::model::channel::Message;
use serenity::model::gateway::Ready; use serenity::model::gateway::Ready;
use serenity::http::Http; use serenity::http::Http;
struct Globals;
impl TypeMapKey for Globals
{
type Value = Arc<AtomicU64>;
}
struct Handler; struct Handler;
#[async_trait] #[async_trait]
@ -59,6 +68,7 @@ async fn main()
println!("Connecting..."); println!("Connecting...");
let intents = GatewayIntents::GUILD_MESSAGES let intents = GatewayIntents::GUILD_MESSAGES
@ -70,9 +80,15 @@ async fn main()
// by Discord for bot users. // by Discord for bot users.
let mut client = Client::builder(&token, intents).event_handler(Handler).await.expect("Err creating client"); let mut client = Client::builder(&token, intents).event_handler(Handler).await.expect("Err creating client");
// TODO: See link for how to add global data to the client:
// Set the global data
// https://github.com/serenity-rs/serenity/blob/current/examples/e12_global_data/src/main.rs // https://github.com/serenity-rs/serenity/blob/current/examples/e12_global_data/src/main.rs
// client.data.write().await.insert::<UserId>(owner); {
// Open the data lock in write mode, so keys can be inserted to it.
let mut data = client.data.write().await;
data.insert::<Globals>(Arc::new(AtomicU64::new(owner.into())));
}
// Finally, start a single shard, and start listening to events. // Finally, start a single shard, and start listening to events.
// //

@ -3,6 +3,7 @@ use rand::prelude::*;
use serenity::{client::Context, model::prelude::ChannelId}; use serenity::{client::Context, model::prelude::ChannelId};
pub const SM_SERVER_ID: u64 = 98929157894836224;
pub const ADMIN_SERVER_ID: u64 = 483735475283165195; pub const ADMIN_SERVER_ID: u64 = 483735475283165195;
pub const ADMIN_COMMAND_CHANNEL_ID: u64 = 1130607621699809443; pub const ADMIN_COMMAND_CHANNEL_ID: u64 = 1130607621699809443;
pub const MAIN_LOG_CHANNEL_ID: u64 = 1130607583007363074; pub const MAIN_LOG_CHANNEL_ID: u64 = 1130607583007363074;

Loading…
Cancel
Save