mirror of
https://forge.gzod01.fr/werobot/discoWeRo-Bot.git
synced 2024-11-17 10:28:03 +00:00
some changes
This commit is contained in:
parent
86975d8a76
commit
62d7684234
5 changed files with 1099 additions and 17 deletions
1
.env
1
.env
|
@ -1 +1,2 @@
|
||||||
DISCORD_TOKEN=MTIzMDE2NjI2NTM3NzU5MTM5Ng.GVqsyl.ZvP2Kigd5VgP4eITdGqAGYfDw58YeXJYSJg4-A
|
DISCORD_TOKEN=MTIzMDE2NjI2NTM3NzU5MTM5Ng.GVqsyl.ZvP2Kigd5VgP4eITdGqAGYfDw58YeXJYSJg4-A
|
||||||
|
MYSQL_PASS=gitpoi27940
|
||||||
|
|
1041
Cargo.lock
generated
1041
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -5,5 +5,8 @@ authors = ["WeRobot <contact@werobot.fr>", "GZod01 <gzod01@gzod01.fr>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
mysql = "25.0.0"
|
||||||
|
serde_json = "1.0.116"
|
||||||
serenity = "0.12"
|
serenity = "0.12"
|
||||||
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
|
3
buttons_role.json
Normal file
3
buttons_role.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"fgc_test_in_lgaw":"1229486844912210011"
|
||||||
|
}
|
62
src/main.rs
62
src/main.rs
|
@ -1,12 +1,30 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use serenity::all::{ComponentInteractionData, ComponentInteractionDataKind, Interaction};
|
// use lazy_static::lazy_static;
|
||||||
use serenity::async_trait;
|
use serenity::all::{ComponentInteractionDataKind, Interaction};
|
||||||
|
use serenity::{async_trait, json};
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
use serde_json::json;
|
||||||
|
use serde_json::Map;
|
||||||
|
// use mysql::prelude::Queryable;
|
||||||
|
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
|
||||||
|
// lazy_static! {
|
||||||
|
// static ref CONN: Mutex<mysql::Conn> = {
|
||||||
|
// let password = env::var("MYSQL_PASS").expect("MySql pass not found in env");
|
||||||
|
// let url = "mysql://disco_wero_bot:{password:?}@localhost:3306/dwrbot_db";
|
||||||
|
// let mut r = Mutex::new(mysql::Conn::new(url).unwrap());
|
||||||
|
// r
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
//static mut conn: Option<mysql::PooledConn>=None;
|
||||||
|
|
||||||
#[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) {
|
||||||
|
@ -23,19 +41,45 @@ impl EventHandler for Handler {
|
||||||
}
|
}
|
||||||
if ["hello", "hi", "bonjour", "hola", "halo"]
|
if ["hello", "hi", "bonjour", "hola", "halo"]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|&s| msg.content.to_lowercase().contains(s))
|
.any(|&s| msg.content.to_lowercase().contains(s))
|
||||||
{
|
{
|
||||||
if let Err(why) = msg.react(ctx, '👋').await {
|
if let Err(why) = msg.react(ctx, '👋').await {
|
||||||
println!("Error reacting message {why:?}");
|
println!("Error reacting message {why:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction){
|
async fn interaction_create(&self, ctx: Context, interaction: Interaction){
|
||||||
if let Interaction::Component(comp) = interaction{
|
if let Interaction::Component(comp) = interaction{
|
||||||
println!("Received component interaction {comp:?}");
|
println!("Received component interaction {comp:?}");
|
||||||
if matches!(comp.data.kind, ComponentInteractionDataKind::Button){
|
if matches!(comp.data.kind, ComponentInteractionDataKind::Button){
|
||||||
let compid = comp.data.custom_id;
|
let compid = comp.data.custom_id;
|
||||||
|
// let guild_id=comp.guild_id;
|
||||||
|
// let channel_id=comp.channel_id;
|
||||||
|
let mut role:String="nulled".to_string();
|
||||||
println!("helloworld {compid:?}");
|
println!("helloworld {compid:?}");
|
||||||
|
// let mut conn = *CONN.lock();
|
||||||
|
// conn.lock().query_iter("select role_id from buttons_callback WHERE
|
||||||
|
// guild_id='{guild_id:?}' AND
|
||||||
|
// channel_id='{channel_id:?}' AND
|
||||||
|
// custom_id='{compid:?}'")
|
||||||
|
// .unwrap()
|
||||||
|
// .for_each(|row| {
|
||||||
|
// let r:String = mysql::from_row(row.unwrap());
|
||||||
|
// role=r;
|
||||||
|
// });
|
||||||
|
let mut json_file = File::open("/home/aurel/gzod_site/discordBots/disco_wero_bot/buttons_roles.json").expect("oh no, file not exist!!!!!!!!");
|
||||||
|
let mut json_file_content = String::new();
|
||||||
|
let _ = json_file.read_to_string(&mut json_file_content).expect("can't read file");
|
||||||
|
let json:Map<String,serde_json::Value> =serde_json::from_str(&json_file_content).expect("JSON was not well-formatted");
|
||||||
|
if json.contains_key("{compid:?}"){
|
||||||
|
role = json["{compid:?}"].to_string();
|
||||||
|
}
|
||||||
|
if role=="nulled"{
|
||||||
|
println!("{compid:?} does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let _= comp.member.unwrap().add_role(ctx,role.parse::<u64>().unwrap()).await.expect("oh no");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +105,8 @@ async fn main() {
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
println!("Client error: {why:?}");
|
println!("Client error: {why:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn main(){
|
// fn main(){
|
||||||
|
|
Loading…
Reference in a new issue