ReOrg: TODO: Init per guild join timer
This commit is contained in:
7
src/commands.rs
Normal file
7
src/commands.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use serenity::framework::standard::macros::{group};
|
||||
pub mod ping;
|
||||
use ping::*;
|
||||
|
||||
#[group]
|
||||
#[commands(ping)]
|
||||
pub struct General;
|
||||
11
src/commands/ping.rs
Normal file
11
src/commands/ping.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use serenity::framework::standard::macros::command;
|
||||
use serenity::framework::standard::CommandResult;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::prelude::Context;
|
||||
|
||||
#[command]
|
||||
pub async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
msg.channel_id.say(&ctx.http, "pong!").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
23
src/events.rs
Normal file
23
src/events.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use serenity::async_trait;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::prelude::Context;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
// Set a handler to be called on the `ready` event. This is called when a
|
||||
// shard is booted, and a READY payload is sent by Discord. This payload
|
||||
// contains data like the current user's guild Ids, current user data,
|
||||
// private channels, and more.
|
||||
//
|
||||
// In this case, just print what the current user's username is.
|
||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
for g_id in ctx.cache.guilds() {
|
||||
let g = ctx.cache.guild(g_id).expect("Unable to fetch guild");
|
||||
println!("Initializing {}...", g.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
src/main.rs
70
src/main.rs
@@ -2,65 +2,28 @@
|
||||
|
||||
use std::env;
|
||||
|
||||
use serenity::async_trait;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::prelude::*;
|
||||
use serenity::framework::standard::macros::{command, group};
|
||||
use serenity::framework::standard::{CommandResult, StandardFramework};
|
||||
use serenity::framework::standard::{StandardFramework};
|
||||
|
||||
#[command]
|
||||
async fn about(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
msg.channel_id.say(&ctx.http, "A simple test bot").await?;
|
||||
// This trait adds the `register_songbird` and `register_songbird_with` methods
|
||||
// to the client builder below, making it easy to install this voice client.
|
||||
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
|
||||
use songbird::SerenityInit;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// Import the `Context` to handle commands.
|
||||
use serenity::client::Context;
|
||||
|
||||
#[command]
|
||||
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
msg.channel_id.say(&ctx.http, "pong!").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
mod commands;
|
||||
use commands::*;
|
||||
|
||||
#[group]
|
||||
#[commands(about, ping)]
|
||||
struct General;
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
// Set a handler for the `message` event - so that whenever a new message
|
||||
// is received - the closure (or function) passed will be called.
|
||||
//
|
||||
// Event handlers are dispatched through a threadpool, and so multiple
|
||||
// events can be dispatched simultaneously.
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.content == "!ping" {
|
||||
// Sending a message can fail, due to a network error, an
|
||||
// authentication error, or lack of permissions to post in the
|
||||
// channel, so log to stdout when some error happens, with a
|
||||
// description of it.
|
||||
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
||||
println!("Error sending message: {:?}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set a handler to be called on the `ready` event. This is called when a
|
||||
// shard is booted, and a READY payload is sent by Discord. This payload
|
||||
// contains data like the current user's guild Ids, current user data,
|
||||
// private channels, and more.
|
||||
//
|
||||
// In this case, just print what the current user's username is.
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
mod events;
|
||||
use events::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Trace async functions
|
||||
tracing_subscriber::fmt::init();
|
||||
// Configure the client with your Discord bot token in the environment.
|
||||
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
// Set gateway intents, which decides what events the bot will be notified about
|
||||
@@ -74,17 +37,14 @@ async fn main() {
|
||||
| GatewayIntents::MESSAGE_CONTENT;
|
||||
|
||||
let framework = StandardFramework::new()
|
||||
.configure(|c| c.prefix("~"))
|
||||
// The `#[group]` (and similarly, `#[command]`) macro generates static instances
|
||||
// containing any options you gave it. For instance, the group `name` and its `commands`.
|
||||
// Their identifiers, names you can use to refer to these instances in code, are an
|
||||
// all-uppercased version of the `name` with a `_GROUP` suffix appended at the end.
|
||||
.configure(|c| c.prefix("ALAN! "))
|
||||
.group(&GENERAL_GROUP);
|
||||
|
||||
let mut client =
|
||||
Client::builder(&token, intents)
|
||||
.event_handler(Handler)
|
||||
.framework(framework)
|
||||
.register_songbird()
|
||||
.await.expect("Err creating client");
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
|
||||
Reference in New Issue
Block a user