mirror of
https://github.com/Noratrieb/discord-court-bot.git
synced 2026-01-14 18:05:02 +01:00
submodules handlers
This commit is contained in:
parent
d9ca14c642
commit
0605eda466
2 changed files with 305 additions and 324 deletions
197
src/handler.rs
197
src/handler.rs
|
|
@ -38,34 +38,7 @@ impl Display for Response {
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||
info!(name = %ready.user.name, "Bot is connected!");
|
||||
|
||||
if let Some(guild_id) = self.dev_guild_id {
|
||||
let guild_commands =
|
||||
GuildId::set_application_commands(&guild_id, &ctx.http, slash_commands).await;
|
||||
|
||||
match guild_commands {
|
||||
Ok(_) => info!("Installed guild slash commands"),
|
||||
Err(error) => error!(?error, "Failed to create global commands"),
|
||||
}
|
||||
}
|
||||
|
||||
if self.set_global_commands {
|
||||
let guild_commands =
|
||||
ApplicationCommand::set_global_application_commands(&ctx.http, slash_commands)
|
||||
.await;
|
||||
match guild_commands {
|
||||
Ok(commands) => info!(?commands, "Created global commands"),
|
||||
Err(error) => error!(?error, "Failed to create global commands"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
impl Handler {
|
||||
async fn handle_guild_member_join(
|
||||
&self,
|
||||
|
|
@ -99,22 +72,25 @@ impl Handler {
|
|||
}
|
||||
}
|
||||
|
||||
#[poise::command(
|
||||
pub mod lawsuit {
|
||||
use super::*;
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
subcommands(
|
||||
"lawsuit_create",
|
||||
"lawsuit_set_category",
|
||||
"lawsuit_close",
|
||||
"lawsuit_clear"
|
||||
"create",
|
||||
"set_category",
|
||||
"close",
|
||||
"clear"
|
||||
)
|
||||
)]
|
||||
pub async fn lawsuit(_: crate::Context<'_>) -> Result<()> {
|
||||
)]
|
||||
pub async fn lawsuit(_: crate::Context<'_>) -> Result<()> {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Einen neuen Gerichtsprozess erstellen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn lawsuit_create(
|
||||
/// Einen neuen Gerichtsprozess erstellen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn create(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Der Kläger"] plaintiff: User,
|
||||
#[description = "Der Angeklagte"] accused: User,
|
||||
|
|
@ -122,7 +98,7 @@ async fn lawsuit_create(
|
|||
#[description = "Der Grund für die Klage"] reason: String,
|
||||
#[description = "Der Anwalt des Klägers"] plaintiff_lawyer: Option<User>,
|
||||
#[description = "Der Anwalt des Angeklagten"] accused_lawyer: Option<User>,
|
||||
) -> Result<()> {
|
||||
) -> Result<()> {
|
||||
lawsuit_create_impl(
|
||||
ctx,
|
||||
plaintiff,
|
||||
|
|
@ -134,78 +110,37 @@ async fn lawsuit_create(
|
|||
)
|
||||
.await
|
||||
.wrap_err("lawsuit_create")
|
||||
}
|
||||
}
|
||||
|
||||
/// Die Rolle für Gefangene setzen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn lawsuit_set_category(
|
||||
/// Die Rolle für Gefangene setzen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn set_category(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Kategorie"] category: Channel,
|
||||
) -> Result<()> {
|
||||
) -> Result<()> {
|
||||
lawsuit_set_category_impl(ctx, category)
|
||||
.await
|
||||
.wrap_err("lawsuit_set_category")
|
||||
}
|
||||
}
|
||||
|
||||
/// Den Gerichtsprozess abschliessen und ein Urteil fällen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn lawsuit_close(
|
||||
/// Den Gerichtsprozess abschliessen und ein Urteil fällen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn close(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Das Urteil"] verdict: String,
|
||||
) -> Result<()> {
|
||||
) -> Result<()> {
|
||||
lawsuit_close_impl(ctx, verdict)
|
||||
.await
|
||||
.wrap_err("lawsuit_close")
|
||||
}
|
||||
}
|
||||
|
||||
/// Alle Rechtsprozessdaten löschen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn lawsuit_clear(ctx: crate::Context<'_>) -> Result<()> {
|
||||
/// Alle Rechtsprozessdaten löschen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn clear(ctx: crate::Context<'_>) -> Result<()> {
|
||||
lawsuit_clear_impl(ctx).await.wrap_err("lawsuit_clear")
|
||||
}
|
||||
}
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
subcommands("prison_set_role", "prison_arrest", "prison_release")
|
||||
)]
|
||||
pub async fn prison(_: crate::Context<'_>) -> Result<()> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
/// Die Rolle für Gefangene setzen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn prison_set_role(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Rolle"] role: Role,
|
||||
) -> Result<()> {
|
||||
prison_set_role_impl(ctx, role)
|
||||
.await
|
||||
.wrap_err("prison_set_role")
|
||||
}
|
||||
|
||||
/// Jemanden einsperren
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn prison_arrest(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Person zum einsperren"] user: User,
|
||||
) -> Result<()> {
|
||||
prison_arrest_impl(ctx, user)
|
||||
.await
|
||||
.wrap_err("prison_arrest")
|
||||
}
|
||||
|
||||
/// Einen Gefangenen freilassen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn prison_release(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Person zum freilassen"] user: User,
|
||||
) -> Result<()> {
|
||||
prison_release_impl(ctx, user)
|
||||
.await
|
||||
.wrap_err("prison_release")
|
||||
}
|
||||
|
||||
async fn lawsuit_create_impl(
|
||||
async fn lawsuit_create_impl(
|
||||
ctx: crate::Context<'_>,
|
||||
plaintiff: User,
|
||||
accused: User,
|
||||
|
|
@ -213,7 +148,7 @@ async fn lawsuit_create_impl(
|
|||
reason: String,
|
||||
plaintiff_lawyer: Option<User>,
|
||||
accused_lawyer: Option<User>,
|
||||
) -> Result<()> {
|
||||
) -> Result<()> {
|
||||
let guild_id = ctx.guild_id().wrap_err("guild_id not found")?;
|
||||
|
||||
let lawsuit = Lawsuit {
|
||||
|
|
@ -243,9 +178,9 @@ async fn lawsuit_create_impl(
|
|||
ctx.say(response.to_string()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn lawsuit_set_category_impl(ctx: crate::Context<'_>, category: Channel) -> Result<()> {
|
||||
async fn lawsuit_set_category_impl(ctx: crate::Context<'_>, category: Channel) -> Result<()> {
|
||||
let guild_id = ctx.guild_id().wrap_err("guild_id not found")?;
|
||||
|
||||
//let channel = channel
|
||||
|
|
@ -268,9 +203,9 @@ async fn lawsuit_set_category_impl(ctx: crate::Context<'_>, category: Channel) -
|
|||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn lawsuit_close_impl(ctx: crate::Context<'_>, verdict: String) -> Result<()> {
|
||||
async fn lawsuit_close_impl(ctx: crate::Context<'_>, verdict: String) -> Result<()> {
|
||||
let guild_id = ctx.guild_id().wrap_err("guild_id not found")?;
|
||||
|
||||
let member = ctx.author_member().await.wrap_err("member not found")?;
|
||||
|
|
@ -336,17 +271,62 @@ async fn lawsuit_close_impl(ctx: crate::Context<'_>, verdict: String) -> Result<
|
|||
ctx.say("ich han en dir abschlosse").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn lawsuit_clear_impl(ctx: crate::Context<'_>) -> Result<()> {
|
||||
async fn lawsuit_clear_impl(ctx: crate::Context<'_>) -> Result<()> {
|
||||
let guild_id = ctx.guild_id().wrap_err("guild_id not found")?;
|
||||
|
||||
ctx.data().mongo.delete_guild(guild_id.into()).await?;
|
||||
ctx.say("alles weg").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn prison_set_role_impl(ctx: crate::Context<'_>, role: Role) -> Result<()> {
|
||||
pub mod prison {
|
||||
use super::*;
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
subcommands("set_role", "arrest", "release")
|
||||
)]
|
||||
pub async fn prison(_: crate::Context<'_>) -> Result<()> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
/// Die Rolle für Gefangene setzen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn set_role(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Rolle"] role: Role,
|
||||
) -> Result<()> {
|
||||
prison_set_role_impl(ctx, role)
|
||||
.await
|
||||
.wrap_err("prison_set_role")
|
||||
}
|
||||
|
||||
/// Jemanden einsperren
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn arrest(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Person zum einsperren"] user: User,
|
||||
) -> Result<()> {
|
||||
prison_arrest_impl(ctx, user)
|
||||
.await
|
||||
.wrap_err("prison_arrest")
|
||||
}
|
||||
|
||||
/// Einen Gefangenen freilassen
|
||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn release(
|
||||
ctx: crate::Context<'_>,
|
||||
#[description = "Die Person zum freilassen"] user: User,
|
||||
) -> Result<()> {
|
||||
prison_release_impl(ctx, user)
|
||||
.await
|
||||
.wrap_err("prison_release")
|
||||
}
|
||||
|
||||
async fn prison_set_role_impl(ctx: crate::Context<'_>, role: Role) -> Result<()> {
|
||||
ctx.data()
|
||||
.mongo
|
||||
.set_prison_role(
|
||||
|
|
@ -358,9 +338,9 @@ async fn prison_set_role_impl(ctx: crate::Context<'_>, role: Role) -> Result<()>
|
|||
ctx.say("isch gsetzt").await.wrap_err("reply")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn prison_arrest_impl(ctx: crate::Context<'_>, user: User) -> Result<()> {
|
||||
async fn prison_arrest_impl(ctx: crate::Context<'_>, user: User) -> Result<()> {
|
||||
let mongo_client = &ctx.data().mongo;
|
||||
let guild_id = ctx.guild_id().wrap_err("guild_id not found")?;
|
||||
let http = &ctx.discord().http;
|
||||
|
|
@ -389,9 +369,9 @@ async fn prison_arrest_impl(ctx: crate::Context<'_>, user: User) -> Result<()> {
|
|||
.await
|
||||
.wrap_err("add guild member role")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn prison_release_impl(ctx: crate::Context<'_>, user: User) -> Result<()> {
|
||||
async fn prison_release_impl(ctx: crate::Context<'_>, user: User) -> Result<()> {
|
||||
let mongo_client = &ctx.data().mongo;
|
||||
let guild_id = ctx.guild_id().wrap_err("guild_id not found")?;
|
||||
let http = &ctx.discord().http;
|
||||
|
|
@ -423,6 +403,7 @@ async fn prison_release_impl(ctx: crate::Context<'_>, user: User) -> Result<()>
|
|||
ctx.say("d'freiheit wartet").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn listener(
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
let token = env::var("DISCORD_TOKEN").wrap_err("DISCORD_TOKEN not found in environment")?;
|
||||
let dev_guild_id = if env::var("DEV").is_ok() {
|
||||
Some(serenity::GuildId(
|
||||
Some(GuildId(
|
||||
env::var("GUILD_ID")
|
||||
.wrap_err("GUILD_ID not found in environment, must be set when DEV is set")?
|
||||
.parse()
|
||||
|
|
@ -106,7 +106,7 @@ async fn main() -> Result<()> {
|
|||
})
|
||||
})
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![handler::lawsuit(), handler::prison(), hello()],
|
||||
commands: vec![handler::lawsuit::lawsuit(), handler::prison::prison(), hello()],
|
||||
on_error: |err| Box::pin(async { handler::error_handler(err).await }),
|
||||
listener: |ctx, event, ctx2, data| {
|
||||
Box::pin(async move { handler::listener(ctx, event, ctx2, data).await })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue