added bot

This commit is contained in:
WanderingPenwing 2024-03-07 08:55:09 +01:00
parent bccfbc7a3f
commit 6ed443b405
4 changed files with 63 additions and 18 deletions

View file

@ -8,3 +8,5 @@ edition = "2021"
[dependencies]
eframe = "0.26.2"
image = "0.24.9"
tokio = { version = "0.2", features = ["macros"] }
serenity = { default-features = false, features = ["client", "gateway", "model", "rustls_backend"], version = "0.9.0-rc.2"}

1
jiji.project Normal file
View file

@ -0,0 +1 @@
{"categories":[{"name":"to do","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"get incoming messages","description":"read","id":2},{"name":"sort messages by origin","description":"// Hello there","id":3},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5}]},{"name":"in progress","content":[]},{"name":"done","content":[]},{"name":"bugs","content":[]},{"name":"+","content":[]}]}

View file

@ -5,32 +5,41 @@ use std::{
time,
sync::Arc,
error::Error,
env,
};
use serenity::{
async_trait,
model::{channel::Message, gateway::Ready},
prelude::*,
};
mod token;
const MAX_FPS : f32 = 30.0;
const HELP_MESSAGE: &str = "Hello there, Human! I am a messenger for the wandering penwing.";
const HELP_COMMAND: &str = "!jiji";
fn main() -> Result<(), eframe::Error> {
let icon_data = load_icon().unwrap_or_default();
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([1200.0, 800.0])
.with_icon(Arc::new(icon_data)),
..Default::default()
};
eframe::run_native(
"Jiji",
options,
Box::new(move |_cc| Box::from(Jiji::default())),
)
}
//fn main() -> Result<(), eframe::Error> {
// let icon_data = load_icon().unwrap_or_default();
//
// let options = eframe::NativeOptions {
// viewport: egui::ViewportBuilder::default()
// .with_inner_size([1200.0, 800.0])
// .with_icon(Arc::new(icon_data)),
// ..Default::default()
// };
//
// eframe::run_native(
// "Jiji",
// options,
// Box::new(move |_cc| Box::from(Jiji::default())),
// )
//}
struct Jiji {
token: String,
next_frame: time::Instant,
}
@ -38,7 +47,6 @@ struct Jiji {
impl Default for Jiji {
fn default() -> Self {
Self {
token: "test".to_string(),
next_frame: time::Instant::now(),
}
}
@ -78,4 +86,37 @@ pub fn load_icon() -> Result<egui::IconData, Box<dyn Error>> {
width: icon_width,
height: icon_height,
})
}
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
if msg.content == HELP_COMMAND {
if let Err(why) = msg.channel_id.say(&ctx.http, HELP_MESSAGE).await {
println!("Error sending message: {:?}", why);
}
}
}
async fn ready(&self, _: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
}
}
#[tokio::main]
async fn main() {
//let token = env::var(token::TOKEN)
//.expect("Expected a token in the environment");
let mut client = Client::new(&token::TOKEN)
.event_handler(Handler)
.await
.expect("Err creating client");
if let Err(why) = client.start().await {
println!("Client error: {:?}", why);
}
}

1
src/token.rs Normal file
View file

@ -0,0 +1 @@
pub const TOKEN : &str = "MTIxNTIwMzEyMTk5NTcxNDU4MQ.G2P14S.kMBadIiCH6Lo8Y_V_VU42WLmBVBkbI39CojiAo";