Compare commits

...

1 Commits

Author SHA1 Message Date
Paul Makles
95db641f8f feat: initialise Discord bridge crate 2023-04-21 22:29:17 +01:00
4 changed files with 1351 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
[workspace]
members = ["crates/*"]
members = ["crates/*", "crates/bridges/*"]
exclude = ["crates/bridges"]
[patch.crates-io]
# mobc-redis = { git = "https://github.com/insertish/mobc", rev = "8b880bb59f2ba80b4c7bc40c649c113d8857a186" }

1294
crates/bridges/discord/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
[package]
name = "revolt-discord-bridge"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serenity = { version = "0.11.5", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

View File

@@ -0,0 +1,45 @@
use std::env;
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::model::channel::Channel;
use serenity::model::gateway::{GatewayIntents, Ready};
use serenity::prelude::*;
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
println!("Received message: {}", msg.content);
if msg.content == "deez" {
if let Ok(Channel::Guild(channel)) = msg.channel(&ctx).await {
channel.send_message(&ctx, |m| {
m.content("this is where a message would usually go")
}).await.unwrap();
}
}
}
async fn ready(&self, _: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
}
}
#[tokio::main]
async fn main() {
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let intents =
GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
let mut client = Client::builder(token, intents)
.event_handler(Handler)
.await
.expect("Error creating client");
if let Err(why) = client.start().await {
println!("Client error: {:?}", why);
}
}