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
133
src/handler.rs
133
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 {
|
impl Handler {
|
||||||
async fn handle_guild_member_join(
|
async fn handle_guild_member_join(
|
||||||
&self,
|
&self,
|
||||||
|
|
@ -99,13 +72,16 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod lawsuit {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
slash_command,
|
slash_command,
|
||||||
subcommands(
|
subcommands(
|
||||||
"lawsuit_create",
|
"create",
|
||||||
"lawsuit_set_category",
|
"set_category",
|
||||||
"lawsuit_close",
|
"close",
|
||||||
"lawsuit_clear"
|
"clear"
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
pub async fn lawsuit(_: crate::Context<'_>) -> Result<()> {
|
pub async fn lawsuit(_: crate::Context<'_>) -> Result<()> {
|
||||||
|
|
@ -114,7 +90,7 @@ pub async fn lawsuit(_: crate::Context<'_>) -> Result<()> {
|
||||||
|
|
||||||
/// Einen neuen Gerichtsprozess erstellen
|
/// Einen neuen Gerichtsprozess erstellen
|
||||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||||
async fn lawsuit_create(
|
async fn create(
|
||||||
ctx: crate::Context<'_>,
|
ctx: crate::Context<'_>,
|
||||||
#[description = "Der Kläger"] plaintiff: User,
|
#[description = "Der Kläger"] plaintiff: User,
|
||||||
#[description = "Der Angeklagte"] accused: User,
|
#[description = "Der Angeklagte"] accused: User,
|
||||||
|
|
@ -138,7 +114,7 @@ async fn lawsuit_create(
|
||||||
|
|
||||||
/// Die Rolle für Gefangene setzen
|
/// Die Rolle für Gefangene setzen
|
||||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||||
async fn lawsuit_set_category(
|
async fn set_category(
|
||||||
ctx: crate::Context<'_>,
|
ctx: crate::Context<'_>,
|
||||||
#[description = "Die Kategorie"] category: Channel,
|
#[description = "Die Kategorie"] category: Channel,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
|
@ -149,7 +125,7 @@ async fn lawsuit_set_category(
|
||||||
|
|
||||||
/// Den Gerichtsprozess abschliessen und ein Urteil fällen
|
/// Den Gerichtsprozess abschliessen und ein Urteil fällen
|
||||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||||
async fn lawsuit_close(
|
async fn close(
|
||||||
ctx: crate::Context<'_>,
|
ctx: crate::Context<'_>,
|
||||||
#[description = "Das Urteil"] verdict: String,
|
#[description = "Das Urteil"] verdict: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
|
@ -160,51 +136,10 @@ async fn lawsuit_close(
|
||||||
|
|
||||||
/// Alle Rechtsprozessdaten löschen
|
/// Alle Rechtsprozessdaten löschen
|
||||||
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
#[poise::command(slash_command, required_permissions = "MANAGE_GUILD")]
|
||||||
async fn lawsuit_clear(ctx: crate::Context<'_>) -> Result<()> {
|
async fn clear(ctx: crate::Context<'_>) -> Result<()> {
|
||||||
lawsuit_clear_impl(ctx).await.wrap_err("lawsuit_clear")
|
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<'_>,
|
ctx: crate::Context<'_>,
|
||||||
plaintiff: User,
|
plaintiff: User,
|
||||||
|
|
@ -345,6 +280,51 @@ async fn lawsuit_clear_impl(ctx: crate::Context<'_>) -> Result<()> {
|
||||||
ctx.say("alles weg").await?;
|
ctx.say("alles weg").await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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<()> {
|
async fn prison_set_role_impl(ctx: crate::Context<'_>, role: Role) -> Result<()> {
|
||||||
ctx.data()
|
ctx.data()
|
||||||
|
|
@ -424,6 +404,7 @@ async fn prison_release_impl(ctx: crate::Context<'_>, user: User) -> Result<()>
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn listener(
|
pub async fn listener(
|
||||||
ctx: &serenity::Context,
|
ctx: &serenity::Context,
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let token = env::var("DISCORD_TOKEN").wrap_err("DISCORD_TOKEN not found in environment")?;
|
let token = env::var("DISCORD_TOKEN").wrap_err("DISCORD_TOKEN not found in environment")?;
|
||||||
let dev_guild_id = if env::var("DEV").is_ok() {
|
let dev_guild_id = if env::var("DEV").is_ok() {
|
||||||
Some(serenity::GuildId(
|
Some(GuildId(
|
||||||
env::var("GUILD_ID")
|
env::var("GUILD_ID")
|
||||||
.wrap_err("GUILD_ID not found in environment, must be set when DEV is set")?
|
.wrap_err("GUILD_ID not found in environment, must be set when DEV is set")?
|
||||||
.parse()
|
.parse()
|
||||||
|
|
@ -106,7 +106,7 @@ async fn main() -> Result<()> {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.options(poise::FrameworkOptions {
|
.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 }),
|
on_error: |err| Box::pin(async { handler::error_handler(err).await }),
|
||||||
listener: |ctx, event, ctx2, data| {
|
listener: |ctx, event, ctx2, data| {
|
||||||
Box::pin(async move { handler::listener(ctx, event, ctx2, data).await })
|
Box::pin(async move { handler::listener(ctx, event, ctx2, data).await })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue