we tweaking

This commit is contained in:
Stachelbeere1248 2025-01-08 13:34:45 +01:00
parent c4af8a0bd0
commit f621f25538
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o
11 changed files with 60 additions and 80 deletions

2
Cargo.lock generated
View file

@ -595,6 +595,7 @@ checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-executor",
"futures-io", "futures-io",
"futures-sink", "futures-sink",
"futures-task", "futures-task",
@ -3418,6 +3419,7 @@ dependencies = [
name = "zmp-bot" name = "zmp-bot"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"futures",
"poise", "poise",
"reqwest 0.12.9", "reqwest 0.12.9",
"serde", "serde",

View file

@ -13,3 +13,4 @@ reqwest = { version = "0.12.9", features = ["json"] }
tokio = { version = "1.42.0", features = ["rt-multi-thread"] } tokio = { version = "1.42.0", features = ["rt-multi-thread"] }
tracing = { version = "0.1.41" } tracing = { version = "0.1.41" }
sqlx = { version = "0.8.2", features = ["sqlite", "sqlx-sqlite", "runtime-tokio"]} sqlx = { version = "0.8.2", features = ["sqlite", "sqlx-sqlite", "runtime-tokio"]}
futures = "0.3.31"

View file

@ -71,13 +71,11 @@ impl Uuid {
let matches = deserialized let matches = deserialized
.player .player
.social_media .social_media
.map(|sm| sm.links) .and_then(|sm| sm.links)
.flatten() .and_then(|l| l.discord)
.map(|l| l.discord) .ok_or(Other(
.flatten() "The Hypixel profile has no Discord account linked. Please follow the steps in <#1256219552568840263>".to_string(),
.ok_or(Other(format!( ))?
"The Hypixel profile has no Discord account linked. Please follow the steps in <#1256219552568840263>",
)))?
== user.name; == user.name;
Ok(matches) Ok(matches)
} }
@ -124,20 +122,20 @@ impl Link {
Ok(self) Ok(self)
} }
} }
#[poise::command(slash_command, subcommands("add", "list"))] #[poise::command(
slash_command,
subcommands("add", "list"),
install_context = "User|Guild",
interaction_context = "Guild|BotDm|PrivateChannel",
)]
pub(crate) async fn account(_ctx: Context<'_>) -> Result<(), Error> { pub(crate) async fn account(_ctx: Context<'_>) -> Result<(), Error> {
// root of slash-commands is not invokable. // root of slash-commands is not invokable.
unreachable!() unreachable!()
} }
#[poise::command( #[poise::command(slash_command, ephemeral = "false")]
slash_command,
install_context = "User|Guild",
interaction_context = "Guild|BotDm|PrivateChannel",
ephemeral = "false"
)]
/// Verify a Minecraft account on the Zombies MultiPlayer Discord. /// Verify a Minecraft account on the Zombies MultiPlayer Discord.
pub(crate) async fn add<'a>( pub(crate) async fn add(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Minecraft username"] #[description = "Minecraft username"]
#[min_length = 2] #[min_length = 2]
@ -238,13 +236,7 @@ pub(crate) async fn add<'a>(
} }
} }
#[poise::command( #[poise::command(slash_command, ephemeral = "true", context_menu_command = "Account list")]
slash_command,
install_context = "User|Guild",
interaction_context = "Guild|BotDm|PrivateChannel",
ephemeral = "true",
context_menu_command = "Account list"
)]
/// List a users linked minecraft Accounts. /// List a users linked minecraft Accounts.
pub(crate) async fn list(ctx: Context<'_>, user: User) -> Result<(), Error> { pub(crate) async fn list(ctx: Context<'_>, user: User) -> Result<(), Error> {
ctx.defer().await?; ctx.defer().await?;

View file

@ -2,15 +2,15 @@ use std::string::String;
use poise::CreateReply; use poise::CreateReply;
use crate::Context;
use crate::error::Error; use crate::error::Error;
use crate::Context;
#[poise::command( #[poise::command(
slash_command, slash_command,
owners_only, owners_only,
install_context = "User", install_context = "User",
interaction_context = "Guild|BotDm|PrivateChannel", interaction_context = "Guild|BotDm|PrivateChannel",
ephemeral = "false", ephemeral = "false"
)] )]
/// Change how many helpstart bots are online, to limit usage of helpstart pings. /// Change how many helpstart bots are online, to limit usage of helpstart pings.
pub(crate) async fn bots( pub(crate) async fn bots(

View file

@ -1,7 +1,7 @@
use std::time::Duration; use std::time::Duration;
use crate::Context;
use crate::error::Error; use crate::error::Error;
use crate::Context;
pub(crate) fn cooldown(ctx: &Context, user: u64, guild: u64) -> Result<(), Error> { pub(crate) fn cooldown(ctx: &Context, user: u64, guild: u64) -> Result<(), Error> {
let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap(); let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap();

View file

@ -2,15 +2,10 @@ use poise::CreateReply;
use serenity::all::CreateAllowedMentions; use serenity::all::CreateAllowedMentions;
use crate::commands::command_helper; use crate::commands::command_helper;
use crate::Context;
use crate::error::Error; use crate::error::Error;
use crate::Context;
#[poise::command( #[poise::command(slash_command, install_context = "Guild", interaction_context = "Guild", ephemeral = "false")]
slash_command,
install_context = "Guild",
interaction_context = "Guild",
ephemeral = "false",
)]
/// Ping the @helpstart to fill a queue. /// Ping the @helpstart to fill a queue.
pub(crate) async fn helpstart( pub(crate) async fn helpstart(
ctx: Context<'_>, ctx: Context<'_>,

View file

@ -7,8 +7,8 @@ use crate::commands::command_helper::cooldown;
use crate::commands::lfg::Difficulty::Normal; use crate::commands::lfg::Difficulty::Normal;
use crate::commands::lfg::Map::*; use crate::commands::lfg::Map::*;
use crate::commands::lfg::Mode::*; use crate::commands::lfg::Mode::*;
use crate::Context;
use crate::error::Error; use crate::error::Error;
use crate::Context;
#[derive(Debug, poise::ChoiceParameter, PartialEq)] #[derive(Debug, poise::ChoiceParameter, PartialEq)]
pub enum Map { pub enum Map {
@ -43,12 +43,7 @@ pub enum Difficulty {
#[name = "R.I.P."] #[name = "R.I.P."]
Rip, Rip,
} }
#[poise::command( #[poise::command(slash_command, install_context = "Guild", interaction_context = "Guild", ephemeral = "false")]
slash_command,
install_context = "Guild",
interaction_context = "Guild",
ephemeral = "false",
)]
/// Find a team for Hypixel Zombies. /// Find a team for Hypixel Zombies.
pub(crate) async fn lfg( pub(crate) async fn lfg(
ctx: Context<'_>, ctx: Context<'_>,

View file

@ -1,21 +1,21 @@
use crate::Context;
use crate::error::Error; use crate::error::Error;
use crate::Context;
const XD: &str = "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⡿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n\ const XD: &str = "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⡿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\\
\n\n\ n\n\\
\n\n\ n\n\\
\n\n\ n\n\\
\n\n\ n\n\\
\n\n\ n\n\\
\n\n\ n\n\\
\n"; n\n";
#[poise::command( #[poise::command(
slash_command, slash_command,
owners_only, owners_only,
install_context = "User|Guild", install_context = "User|Guild",
interaction_context = "Guild|BotDm|PrivateChannel", interaction_context = "Guild|BotDm|PrivateChannel",
ephemeral = "false", ephemeral = "false"
)] )]
/// Useless command to check if the bot is online. /// Useless command to check if the bot is online.
pub(crate) async fn xd(ctx: Context<'_>) -> Result<(), Error> { pub(crate) async fn xd(ctx: Context<'_>) -> Result<(), Error> {

View file

@ -1,5 +1,5 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
use poise::{CreateReply, FrameworkError}; use poise::{CreateReply, FrameworkError};
use std::fmt::{Display, Formatter, Result as FmtResult};
use crate::Data; use crate::Data;
@ -54,7 +54,7 @@ pub(crate) async fn handle_error<'a>(error: FrameworkError<'a, Data, Error>) {
match error { match error {
FrameworkError::Command { error, ctx, .. } => { FrameworkError::Command { error, ctx, .. } => {
reply_fail_handler!(ctx.send(CreateReply::default().content(error.to_string()).ephemeral(true))) reply_fail_handler!(ctx.send(CreateReply::default().content(error.to_string()).ephemeral(true)))
}, }
FrameworkError::CommandStructureMismatch { description, ctx, .. } => { FrameworkError::CommandStructureMismatch { description, ctx, .. } => {
reply_fail_handler!(ctx.send( reply_fail_handler!(ctx.send(
CreateReply::default() CreateReply::default()

View file

@ -1,5 +1,4 @@
use serenity::all::ButtonStyle::Success; use serenity::all::ButtonStyle::Success;
use serenity::all::ComponentInteractionDataKind;
use serenity::all::Context; use serenity::all::Context;
use serenity::all::CreateActionRow; use serenity::all::CreateActionRow;
use serenity::all::CreateButton; use serenity::all::CreateButton;
@ -12,6 +11,7 @@ use serenity::all::Interaction;
use serenity::all::ReactionType; use serenity::all::ReactionType;
use serenity::all::RoleId; use serenity::all::RoleId;
use serenity::all::{ButtonStyle, ComponentInteraction}; use serenity::all::{ButtonStyle, ComponentInteraction};
use serenity::all::{ComponentInteractionDataKind, CreateInteractionResponse};
use crate::error::Error; use crate::error::Error;
use crate::Data; use crate::Data;
@ -25,23 +25,20 @@ pub(crate) async fn component(ctx: &Context, interaction: &Interaction, data: &D
} }
async fn button(ctx: &Context, mut interaction: ComponentInteraction, data: &Data) -> Result<(), Error> { async fn button(ctx: &Context, mut interaction: ComponentInteraction, data: &Data) -> Result<(), Error> {
let m = &interaction.message; let u = interaction.message.mentions.first().expect("Message did not mention a user.").id;
let u = m.mentions.first().expect("Message did not mention a user.");
match interaction.data.custom_id.as_str() { match interaction.data.custom_id.as_str() {
"accept_verification" => { "accept_verification" => {
let member = m let member = interaction
.message
.guild_id .guild_id
.unwrap_or(GuildId::new(1256217633959841853_u64)) .unwrap_or(GuildId::new(1256217633959841853_u64))
.member(ctx, u.id) .member(ctx, u)
.await?; .await?;
member.add_role(ctx, RoleId::new(1256218805911425066_u64)).await?; let (_, _, _dm, _) = futures::try_join!(
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)).await?; member.add_role(ctx, RoleId::new(1256218805911425066_u64)),
let _dm = u member.remove_role(ctx, RoleId::new(1256253358701023232_u64)),
.direct_message(ctx, CreateMessage::new().content("Your verified minecraft account was approved.")) u.direct_message(ctx, CreateMessage::new().content("Your verified minecraft account was approved.")),
.await?; interaction.message.edit(
interaction
.message
.edit(
ctx, ctx,
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![ EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
CreateButton::new("accept_verification") CreateButton::new("accept_verification")
@ -57,16 +54,14 @@ async fn button(ctx: &Context, mut interaction: ComponentInteraction, data: &Dat
.style(ButtonStyle::Primary), .style(ButtonStyle::Primary),
])]), ])]),
) )
.await?; )?;
interaction.create_response(ctx, CreateInteractionResponse::Acknowledge).await?;
Ok(()) Ok(())
} }
"deny_verification" => { "deny_verification" => {
let _dm = u let (_dm, _) = futures::try_join!(
.direct_message(ctx, CreateMessage::new().content("Your verified minecraft account was denied.")) u.direct_message(ctx, CreateMessage::new().content("Your verified minecraft account was denied.")),
.await?; interaction.message.edit(
interaction
.message
.edit(
ctx, ctx,
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![ EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
CreateButton::new("accept_verification") CreateButton::new("accept_verification")
@ -82,8 +77,8 @@ async fn button(ctx: &Context, mut interaction: ComponentInteraction, data: &Dat
.style(ButtonStyle::Primary), .style(ButtonStyle::Primary),
])]), ])]),
) )
.await?; )?;
interaction.create_response(ctx, CreateInteractionResponse::Acknowledge).await?;
Ok(()) Ok(())
} }
"list_accounts" => { "list_accounts" => {

View file

@ -6,9 +6,9 @@ use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use poise::serenity_prelude as serenity; use poise::serenity_prelude as serenity;
use serenity::{FullEvent, model::id::UserId};
use serenity::all::{ActivityData, InteractionType, RoleId}; use serenity::all::{ActivityData, InteractionType, RoleId};
use serenity::prelude::GatewayIntents; use serenity::prelude::GatewayIntents;
use serenity::{model::id::UserId, FullEvent};
use sqlx::Sqlite; use sqlx::Sqlite;
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -96,7 +96,7 @@ async fn event_handler(
match event { match event {
FullEvent::Ready { data_about_bot, .. } => { FullEvent::Ready { data_about_bot, .. } => {
println!("Logged in as '{}'!", data_about_bot.user.name); println!("Logged in as '{}'!", data_about_bot.user.name);
}, }
FullEvent::GuildMemberAddition { new_member } => { FullEvent::GuildMemberAddition { new_member } => {
if new_member.guild_id.get() == 1256217633959841853_u64 { if new_member.guild_id.get() == 1256217633959841853_u64 {
new_member.add_role(ctx, RoleId::new(1256253358701023232_u64)).await?; new_member.add_role(ctx, RoleId::new(1256253358701023232_u64)).await?;
@ -106,13 +106,13 @@ async fn event_handler(
if interaction.application_id().get() == 1165594074473037824 && interaction.kind() == InteractionType::Component { if interaction.application_id().get() == 1165594074473037824 && interaction.kind() == InteractionType::Component {
handlers::bot_interaction::component(ctx, interaction, data).await?; handlers::bot_interaction::component(ctx, interaction, data).await?;
} }
}, }
FullEvent::Message { new_message } => { FullEvent::Message { new_message } => {
handlers::message::on_create(ctx, new_message).await?; handlers::message::on_create(ctx, new_message).await?;
}, }
FullEvent::ThreadCreate { thread } => { FullEvent::ThreadCreate { thread } => {
handlers::thread::on_create(ctx, thread).await?; handlers::thread::on_create(ctx, thread).await?;
}, }
_ => {} _ => {}
} }
Ok(()) Ok(())