did stuff
This commit is contained in:
@@ -0,0 +1,83 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use entities::{channel, members, messages, server};
|
||||||
|
use sea_orm::{ColIdx, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
|
||||||
|
use serenity::all::{
|
||||||
|
CommandInteraction, Context, CreateCommand, CreateEmbed, CreateInteractionResponse,
|
||||||
|
CreateInteractionResponseMessage, InteractionContext,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::common::error_msg;
|
||||||
|
|
||||||
|
pub struct Channelretrive {}
|
||||||
|
|
||||||
|
impl Channelretrive {
|
||||||
|
pub async fn run(
|
||||||
|
db: &DatabaseConnection,
|
||||||
|
ctx: &Context,
|
||||||
|
command: &CommandInteraction,
|
||||||
|
) -> CreateInteractionResponse {
|
||||||
|
let invoker_id = command.user.id.get() as i64;
|
||||||
|
let channel_id = command.channel_id.get() as i64;
|
||||||
|
// let guild_id = command.guild_id.unwrap().get() as i64;
|
||||||
|
// let guild_name = command.guild_id.unwrap().name(&ctx.cache).unwrap();
|
||||||
|
|
||||||
|
let channel_db = channel::Model::get_or_create(channel_id, db).await;
|
||||||
|
|
||||||
|
if let Err(e) = channel_db {
|
||||||
|
return error_msg(Box::new(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// let guild_db = server::Model::get_or_create(guild_id, guild_name, db).await;
|
||||||
|
//
|
||||||
|
// if let Err(e) = guild_db {
|
||||||
|
// return error_msg(Box::new(e));
|
||||||
|
// }
|
||||||
|
|
||||||
|
let messages_by_channels = messages::Entity::find()
|
||||||
|
.filter(messages::Column::IdChannel.eq(channel_db.unwrap()))
|
||||||
|
.all(db)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut user_lookup: HashMap<i32, String> = HashMap::new();
|
||||||
|
let mut user_msg_amount: HashMap<String, i32> = HashMap::new();
|
||||||
|
|
||||||
|
for x in messages_by_channels {
|
||||||
|
if let Some(user) = user_lookup.get(&x.id_sender) {
|
||||||
|
if let Some(user_amount) = user_msg_amount.get(user) {
|
||||||
|
user_msg_amount.insert(user.to_string(), (user_amount + 1));
|
||||||
|
} else {
|
||||||
|
user_msg_amount.insert(user.clone(), 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let memebr = members::Entity::find_by_id(x.id_sender)
|
||||||
|
.one(db)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
user_lookup.insert(memebr.id, memebr.name.clone());
|
||||||
|
user_msg_amount.insert(memebr.name, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut summary_string: String = String::new();
|
||||||
|
for x in &user_msg_amount {
|
||||||
|
summary_string.push_str(format!("{} - {}\n", x.0, x.1).as_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
let embed = CreateEmbed::new()
|
||||||
|
.title("Summary")
|
||||||
|
.description(format!("{}", summary_string));
|
||||||
|
|
||||||
|
let reply = CreateInteractionResponseMessage::new().embed(embed);
|
||||||
|
|
||||||
|
CreateInteractionResponse::Message(reply)
|
||||||
|
}
|
||||||
|
pub fn register() -> CreateCommand {
|
||||||
|
CreateCommand::new("retriveChannel")
|
||||||
|
.name("channeldata")
|
||||||
|
.description("description")
|
||||||
|
.contexts(vec![InteractionContext::Guild])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
use sea_orm::DatabaseConnection;
|
||||||
|
use serenity::all::{
|
||||||
|
CommandInteraction, Context, CreateCommand, CreateInteractionResponse, InteractionContext,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct Fetch;
|
||||||
|
|
||||||
|
// This is "possible" but with ratelimiting, it'll take a long long long time to rip a medium sized
|
||||||
|
// server
|
||||||
|
|
||||||
|
impl Fetch {
|
||||||
|
pub fn register() -> CreateCommand {
|
||||||
|
CreateCommand::new("retriveChannel")
|
||||||
|
.name("channeldata")
|
||||||
|
.description("description")
|
||||||
|
.contexts(vec![InteractionContext::Guild])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,15 @@ use std::error::Error;
|
|||||||
use entities::{channel, content, members, messages, server};
|
use entities::{channel, content, members, messages, server};
|
||||||
use migration::prelude::{DateTime, Utc};
|
use migration::prelude::{DateTime, Utc};
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
|
use sea_orm::{ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
|
||||||
use serenity::all::{Context, Message};
|
use serenity::all::{Context, Message, VoiceState};
|
||||||
|
|
||||||
|
pub async fn log_vc_event(
|
||||||
|
db: &DatabaseConnection,
|
||||||
|
ctx: &Context,
|
||||||
|
vc: VoiceState,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn log_message(
|
pub async fn log_message(
|
||||||
db: &DatabaseConnection,
|
db: &DatabaseConnection,
|
||||||
|
|||||||
+22
-7
@@ -6,16 +6,18 @@ use migration::{Migrator, MigratorTrait};
|
|||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
ActiveModelTrait, ColumnTrait, Database, DatabaseConnection, EntityTrait, Iden, QueryFilter,
|
ActiveModelTrait, ColumnTrait, Database, DatabaseConnection, EntityTrait, Iden, QueryFilter,
|
||||||
};
|
};
|
||||||
use serenity::all::{Command, Interaction, Ready};
|
use serenity::all::{Command, Interaction, Ready, VoiceState};
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::model::guild;
|
use serenity::model::guild;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
use crate::logger::log_message;
|
use crate::logger::{log_message, log_vc_event};
|
||||||
|
|
||||||
|
mod channelcommand;
|
||||||
mod command;
|
mod command;
|
||||||
mod common;
|
mod common;
|
||||||
|
mod fetchcommand;
|
||||||
mod logger;
|
mod logger;
|
||||||
|
|
||||||
struct Bot {
|
struct Bot {
|
||||||
@@ -32,15 +34,25 @@ impl EventHandler for Bot {
|
|||||||
}
|
}
|
||||||
log_message(&self.db, &ctx, msg).await.unwrap();
|
log_message(&self.db, &ctx, msg).await.unwrap();
|
||||||
}
|
}
|
||||||
|
async fn voice_state_update(&self, ctx: Context, _old: Option<VoiceState>, new: VoiceState) {
|
||||||
|
log_vc_event(&self.db, &ctx, new).await.unwrap();
|
||||||
|
}
|
||||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||||
if let Interaction::Command(command) = interaction {
|
if let Interaction::Command(command) = interaction {
|
||||||
println!("Received command interaction: {command:#?}");
|
println!("Received command interaction: {command:#?}");
|
||||||
|
|
||||||
|
println!("{:#?}", command.data.name.as_str());
|
||||||
|
|
||||||
let content = match command.data.name.as_str() {
|
let content = match command.data.name.as_str() {
|
||||||
"userdata" => Some(command::Retrive::run(&self.db, &ctx, &command).await),
|
"userdata" => Some(command::Retrive::run(&self.db, &ctx, &command).await),
|
||||||
|
"channeldata" => {
|
||||||
|
Some(channelcommand::Channelretrive::run(&self.db, &ctx, &command).await)
|
||||||
|
}
|
||||||
_ => Some(serenity::all::CreateInteractionResponse::Pong),
|
_ => Some(serenity::all::CreateInteractionResponse::Pong),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
println!("{:#?}", content);
|
||||||
|
|
||||||
if let Some(content) = content {
|
if let Some(content) = content {
|
||||||
if let Err(why) = command.create_response(&ctx.http, content).await {
|
if let Err(why) = command.create_response(&ctx.http, content).await {
|
||||||
println!("Cannot respond to slash command: {why}");
|
println!("Cannot respond to slash command: {why}");
|
||||||
@@ -51,10 +63,12 @@ impl EventHandler for Bot {
|
|||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
println!("{} is connected!", ready.user.name);
|
println!("{} is connected!", ready.user.name);
|
||||||
|
|
||||||
let global_command =
|
Command::create_global_command(&ctx.http, command::Retrive::register())
|
||||||
Command::create_global_command(&ctx.http, command::Retrive::register()).await;
|
.await
|
||||||
|
.unwrap();
|
||||||
println!("I created the following global slash command: {global_command:#?}");
|
Command::create_global_command(&ctx.http, channelcommand::Channelretrive::register())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +83,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// Set gateway intents, which decides what events the bot will be notified about
|
// Set gateway intents, which decides what events the bot will be notified about
|
||||||
let intents = GatewayIntents::GUILD_MESSAGES
|
let intents = GatewayIntents::GUILD_MESSAGES
|
||||||
| GatewayIntents::DIRECT_MESSAGES
|
| GatewayIntents::DIRECT_MESSAGES
|
||||||
| GatewayIntents::MESSAGE_CONTENT;
|
| GatewayIntents::MESSAGE_CONTENT
|
||||||
|
| GatewayIntents::GUILD_VOICE_STATES;
|
||||||
|
|
||||||
let bot = Bot { db: dbc };
|
let bot = Bot { db: dbc };
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Id
|
||||||
|
Id_User
|
||||||
|
Event
|
||||||
|
Timestamp
|
||||||
|
|
||||||
|
enum event :
|
||||||
|
- Joined Vc
|
||||||
|
- Left Vc
|
||||||
|
- Started Screenshare
|
||||||
|
- Stopped Screenshare
|
||||||
|
- Muted
|
||||||
|
- Unmuted
|
||||||
|
- Deafened
|
||||||
|
- Undeafened
|
||||||
Reference in New Issue
Block a user