bot read message and get servers
This commit is contained in:
parent
f8ec903a2c
commit
2d9ea54292
|
@ -9,5 +9,5 @@ edition = "2021"
|
||||||
eframe = "0.26.2"
|
eframe = "0.26.2"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
image = "0.24.9"
|
image = "0.24.9"
|
||||||
serenity = { default-features = false, features = ["client", "gateway", "model", "rustls_backend"], version = "0.9.0-rc.2"}
|
serenity = { default-features = false, features = ["client", "gateway", "model", "rustls_backend", "cache", "http"], version = "0.9.0-rc.2"}
|
||||||
tokio = {features = ["macros"], version = "0.2"}
|
tokio = {features = ["macros"], version = "0.2"}
|
||||||
|
|
20
src/bot.rs
20
src/bot.rs
|
@ -14,27 +14,39 @@ struct Handler;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn message(&self, ctx: Context, msg: Message) {
|
async fn message(&self, ctx: Context, msg: Message) {
|
||||||
|
println!("Message received : '{}' from {}", msg.content, msg.author);
|
||||||
if msg.content == HELP_COMMAND {
|
if msg.content == HELP_COMMAND {
|
||||||
|
println!("Message is command");
|
||||||
if let Err(why) = msg.channel_id.say(&ctx.http, HELP_MESSAGE).await {
|
if let Err(why) = msg.channel_id.say(&ctx.http, HELP_MESSAGE).await {
|
||||||
println!("Error sending message: {:?}", why);
|
println!("Error sending message: {:?}", why);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
println!("Successfuly sent message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ready(&self, _: Context, ready: Ready) {
|
async fn ready(&self, context: Context, ready: Ready) {
|
||||||
println!("{} is connected!", ready.user.name);
|
println!("{} is connected!", ready.user.name);
|
||||||
|
let guilds = context.cache.guilds().await;
|
||||||
|
|
||||||
|
for guild_id in guilds {
|
||||||
|
let guild_name : String = if let Some(guild) = context.cache.guild(guild_id).await {
|
||||||
|
guild.name.clone()
|
||||||
|
} else {
|
||||||
|
"not found".to_string()
|
||||||
|
};
|
||||||
|
println!("Guild : '{}' ({})", guild_id, guild_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_discord_bot() {
|
pub async fn start_discord_bot() {
|
||||||
println!("Creation process started");
|
println!("Bot connection process started...");
|
||||||
let maybe_client = Client::builder(token::TOKEN)
|
let maybe_client = Client::builder(token::TOKEN)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
.await
|
.await
|
||||||
.map_err(|why| format!("Client error: {:?}", why));
|
.map_err(|why| format!("Client error: {:?}", why));
|
||||||
|
|
||||||
println!("Got a result");
|
|
||||||
|
|
||||||
if let Ok(mut client) = maybe_client {
|
if let Ok(mut client) = maybe_client {
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
println!("Client error: {:?}", why);
|
println!("Client error: {:?}", why);
|
||||||
|
|
|
@ -8,10 +8,8 @@ mod bot;
|
||||||
const MAX_FPS: f32 = 30.0;
|
const MAX_FPS: f32 = 30.0;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("hello there");
|
let _handle = thread::spawn(|| {
|
||||||
|
println!("Bot thread spawned");
|
||||||
let handle = thread::spawn(|| {
|
|
||||||
println!("general kenobi");
|
|
||||||
let mut rt = Runtime::new().unwrap();
|
let mut rt = Runtime::new().unwrap();
|
||||||
rt.block_on(bot::start_discord_bot());
|
rt.block_on(bot::start_discord_bot());
|
||||||
});
|
});
|
||||||
|
@ -25,7 +23,7 @@ fn gui() {
|
||||||
|
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
viewport: egui::ViewportBuilder::default()
|
viewport: egui::ViewportBuilder::default()
|
||||||
.with_inner_size([1200.0, 800.0])
|
.with_inner_size([400.0, 300.0])
|
||||||
.with_icon(Arc::new(icon_data)),
|
.with_icon(Arc::new(icon_data)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue