Basic Serenity Config

This commit is contained in:
2023-03-03 15:08:43 -05:00
parent 2c7147a287
commit 5bb7a558f4
4 changed files with 2202 additions and 7 deletions

2091
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,15 @@
[package]
name = "New-Alan"
name = "new_alan"
version = "0.0.1"
edition = "2023"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
tracing-futures = "0.2.5"
serenity = { version = "0.11.5", features = ["voice", "client", "rustls_backend", "standard_framework"] }
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread", "signal"] }
songbird = "0.3.1"

View File

@@ -33,12 +33,18 @@
commonArgs = {
inherit src;
nativeBuildInputs = with pkgs; [
cmake
];
buildInputs = [
# Add additional build inputs here
] ++ lib.optionals pkgs.stdenv.isDarwin [
] ++ lib.optionals pkgs.stdenv.isDarwin ([
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
] ++ (with pkgs.darwin.apple_sdk.frameworks; [
Security
]));
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
@@ -116,6 +122,7 @@
nativeBuildInputs = with pkgs; [
cargo
rustc
rust-analyzer
];
};
});

View File

@@ -1,3 +1,95 @@
fn main() {
println!("Hello, hydra!");
/* TODO: Use tracing for better debugging following events */
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};
#[command]
async fn about(ctx: &Context, msg: &Message) -> CommandResult {
msg.channel_id.say(&ctx.http, "A simple test bot").await?;
Ok(())
}
#[command]
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
msg.channel_id.say(&ctx.http, "pong!").await?;
Ok(())
}
#[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);
}
}
#[tokio::main]
async fn main() {
// 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
let intents = GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILD_VOICE_STATES
| GatewayIntents::GUILD_MESSAGE_REACTIONS
| GatewayIntents::GUILD_MESSAGE_TYPING
| GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::DIRECT_MESSAGE_REACTIONS
| GatewayIntents::DIRECT_MESSAGE_TYPING
| 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.
.group(&GENERAL_GROUP);
let mut client =
Client::builder(&token, intents)
.event_handler(Handler)
.framework(framework)
.await.expect("Err creating client");
if let Err(why) = client.start().await {
println!("Client error: {:?}", why);
}
}