vps ready

This commit is contained in:
Stachelbeere1248 2024-01-17 22:16:49 +01:00
parent 6683cef920
commit edd4c0fd3a
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o
9 changed files with 264 additions and 3277 deletions

3368
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,14 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
poise = "0.5.6" poise = "0.6.1"
serenity = { version = "0.12.0", default-features = false, features = ["client", "gateway", "model", "rustls_backend", "utils"]} serenity = { version = "0.12.0", default-features = false, features = ["client", "gateway", "model", "rustls_backend", "utils", "framework"] }
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "rt"] } tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "rt"] }
env_logger = "0.10.0" env_logger = "0.10.0"
shuttle-secrets = "0.35.2"
shuttle-poise = "0.35.2"
shuttle-runtime = "0.35.2"
anyhow = "1.0.75" anyhow = "1.0.75"
tracing = "0.1.40" tracing = "0.1.40"
regex = "1.10.2" regex = "1.10.2"
cargo-shuttle = { version = "0.35.2" }

View file

@ -1,5 +1,5 @@
use crate::{Context, Error};
use crate::commands::{command_helper, helpstart}; use crate::commands::{command_helper, helpstart};
use crate::{Context, Error};
use std::string::String; use std::string::String;
#[poise::command(slash_command, guild_only)] #[poise::command(slash_command, guild_only)]
@ -8,7 +8,7 @@ pub(crate) async fn bots(
#[min = 0_u8] #[min = 0_u8]
#[description = "default: 0"] #[description = "default: 0"]
bots: u8 bots: u8,
) -> Result<(), Error> { ) -> Result<(), Error> {
helpstart::set_bots_available(bots).await; helpstart::set_bots_available(bots).await;

View file

@ -1,14 +1,18 @@
use std::time::Duration;
use crate::{Context, Error}; use crate::{Context, Error};
use serenity::all::CreateAllowedMentions;
use std::time::Duration;
pub(crate) async fn send( pub(crate) async fn send(ctx: Context<'_>, reply: String) -> Result<(), Error> {
ctx: Context<'_>,
reply: String
) -> Result<(), Error> {
if let Err(why) = ctx if let Err(why) = ctx
.send(|m| { .send(poise::CreateReply {
m.content(reply) content: Some(reply),
.allowed_mentions(|am| am.parse(poise::serenity_prelude::ParseValue::Roles)) embeds: vec![],
attachments: vec![],
ephemeral: None,
components: None,
allowed_mentions: Some(CreateAllowedMentions::new().all_roles(true)),
reply: false,
__non_exhaustive: (),
}) })
.await .await
{ {
@ -17,21 +21,22 @@ pub(crate) async fn send(
Ok(()) Ok(())
} }
pub(crate) fn cooldown( pub(crate) fn cooldown(ctx: &Context, user: u64, global: u64) -> Option<Result<(), Error>> {
ctx: &Context,
user: u64,
global: u64
) -> Option<Result<(), Error>> {
let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap(); let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap();
let mut cooldown_durations = poise::CooldownConfig::default(); let cooldown_durations = poise::CooldownConfig {
cooldown_durations.user = Some(Duration::from_secs(user)); global: Some(Duration::from_secs(global)),
cooldown_durations.global = Some(Duration::from_secs(global)); user: Some(Duration::from_secs(user)),
guild: None,
match cooldown_tracker.remaining_cooldown_2(*ctx, &cooldown_durations) { channel: None,
Some(remaining) => member: None,
Some(Err(format!("Please wait {} seconds", remaining.as_secs()).into())), __non_exhaustive: (),
};
match cooldown_tracker.remaining_cooldown((*ctx).cooldown_context(), &cooldown_durations) {
Some(remaining) => Some(Err(
format!("Please wait {} seconds", remaining.as_secs()).into()
)),
None => { None => {
cooldown_tracker.start_cooldown(*ctx); cooldown_tracker.start_cooldown((*ctx).cooldown_context());
None None
} }
} }

View file

@ -1,5 +1,5 @@
use crate::{Context, Error};
use crate::commands::command_helper; use crate::commands::command_helper;
use crate::{Context, Error};
static mut BOTS_AVAILABLE: u8 = 0; static mut BOTS_AVAILABLE: u8 = 0;
@ -9,26 +9,21 @@ pub(crate) async fn helpstart(
#[min = 1_u8] #[min = 1_u8]
#[max = 3_u8] #[max = 3_u8]
#[description = "default: 3"] #[description = "amount of players in your party, DO NOT include bots"]
#[rename = "needed"] #[rename = "current"]
needed_players: u8 current_players: u8,
) -> Result<(), Error> { ) -> Result<(), Error> {
let needed_players = 4 - current_players;
let bots = unsafe { BOTS_AVAILABLE }; let bots = unsafe { BOTS_AVAILABLE };
let reply = if bots >= needed_players { let reply = if bots >= needed_players {
"Bots available. Please use the Zombies Helpstart v2 Bot in the bot-commands channel instead.".to_string() "Bots available. Please use <@424767825001971715> in the bot-commands channel instead."
.to_string()
} else { } else {
if let Some(value) = command_helper::cooldown( if let Some(value) = command_helper::cooldown(&ctx, 1200, 600) {
&ctx,
1200,
600
) {
return value; return value;
}; };
format!( format!("<@&1008075054971621448>\nneed: {}", needed_players - bots)
"<@&1008075054971621448>\nneed: {}"
, needed_players - bots
)
}; };
command_helper::send(ctx, reply).await command_helper::send(ctx, reply).await

View file

@ -5,9 +5,10 @@ use crate::commands::lfg::Mode::*;
//from main.rs //from main.rs
use crate::{Context, Error}; use crate::{Context, Error};
// //
use crate::commands::command_helper;
use poise::ChoiceParameter;
use serenity::model::mention::Mention; use serenity::model::mention::Mention;
use serenity::model::mention::Mention::Role; use serenity::model::mention::Mention::Role;
use crate::commands::command_helper;
#[derive(Debug, poise::ChoiceParameter, PartialEq)] #[derive(Debug, poise::ChoiceParameter, PartialEq)]
pub enum Map { pub enum Map {
@ -67,32 +68,27 @@ pub(crate) async fn lfg(
#[description = "optional extra message"] #[description = "optional extra message"]
#[rename = "message"] #[rename = "message"]
note: Option<String>, note: Option<String>,
) -> Result<(), Error> { ) -> Result<(), Error> {
if let Some(value) = command_helper::cooldown( if let Some(value) = command_helper::cooldown(&ctx, 600, 300) {
&ctx,
600,
300
) {
return value; return value;
} }
let current = current_players.unwrap_or(1); let current = current_players.unwrap_or(1);
let mut desired = desired_players.unwrap_or(4); let mut desired = desired_players.unwrap_or(4);
if current >= desired { desired = 4 } if current >= desired {
desired = 4
}
let map_name: &str = map.name(); let map_name: &str = map.name();
let ping: Mention; let ping: Mention;
match mode { match mode {
Casual => match map { Casual => match map {
DeadEnd => ping = Role(1005837123921915914.into()), DeadEnd => ping = Role(1005837123921915914.into()),
BadBlood => ping = Role(1140190470698438666.into()), BadBlood => ping = Role(1140190470698438666.into()),
AlienArcadium => ping = Role(1105917281898336356.into()) AlienArcadium => ping = Role(1105917281898336356.into()),
}, },
Speedrun => ping = Role(1005836989595144243.into()), Speedrun => ping = Role(1005836989595144243.into()),
Challenge => ping = Role(1005836864680361994.into()), Challenge => ping = Role(1005836864680361994.into()),
Event => ping = Role(1175116511095050331.into()) Event => ping = Role(1175116511095050331.into()),
} }
let diff_name: &str = if map != AlienArcadium { let diff_name: &str = if map != AlienArcadium {
difficulty.unwrap_or(Normal).name() difficulty.unwrap_or(Normal).name()
@ -100,8 +96,6 @@ pub(crate) async fn lfg(
Normal.name() Normal.name()
}; };
let mut reply = format!( let mut reply = format!(
"{c}/{d} {e} {f} {b}", "{c}/{d} {e} {f} {b}",
b = ping, b = ping,
@ -121,6 +115,5 @@ pub(crate) async fn lfg(
} }
} }
command_helper::send(ctx, reply).await command_helper::send(ctx, reply).await
} }

View file

@ -1,6 +1,5 @@
pub(crate) mod bots;
pub(crate) mod command_helper;
pub(crate) mod helpstart;
pub(crate) mod lfg; pub(crate) mod lfg;
pub(crate) mod xd; pub(crate) mod xd;
pub(crate) mod helpstart;
pub(crate) mod command_helper;
pub(crate) mod bots;

View file

@ -3,9 +3,7 @@ use crate::{Context, Error};
const XD:&str = "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⡿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣧⣄⡀⠀⠀⠀⢀⣠⣼⣿⣿⣿⣿⣧⣄⡀⠀⠀⠀⣀⣤⣼⣷⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠻⣿⣿⣿⣿⣿⣿⠟⠀⠀⢀⣼⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣶⣦⣄⡀⠀⠀⠙⢿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠙⣿⣿⣿⣿⠋⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠈⢿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠈⢿⡿⠁⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⠀⠀⢸⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡗⠀⠀⠀⠐⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⠀⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⣠⡀⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀⠀⣰⣿⣷⡄⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⣾⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⡟⠁⠀⢀⣼⣿⣿⣿⣿⣆⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⢀⣼⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⠋⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠙⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⣠⣾⣿⣿⣿⣿⣿\n⣿⣿⣿⠿⠛⠁⠀⠀⠀⠙⠻⣿⣿⣿⣿⣿⡿⠟⠋⠀⠀⠀⠈⠛⠻⡿⠟⠛⠁⠀⠀⠈⠉⠉⠉⠉⠀⠀⠀⠀⣀⣴⣾⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣶⣶⣶⣶⣶⣶⣶⣶⣿⣿⣿⣿⣿⣷⣶⣶⣶⣶⣶⣶⣶⣶⣷⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"; const XD:&str = "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⡿⠿⠿⠿⠿⠿⠿⠿⢿⡿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣧⣄⡀⠀⠀⠀⢀⣠⣼⣿⣿⣿⣿⣧⣄⡀⠀⠀⠀⣀⣤⣼⣷⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠻⣿⣿⣿⣿⣿⣿⠟⠀⠀⢀⣼⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣶⣦⣄⡀⠀⠀⠙⢿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠙⣿⣿⣿⣿⠋⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠈⢿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠈⢿⡿⠁⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⠀⠀⢸⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡗⠀⠀⠀⠐⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⠀⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⣠⡀⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀⠀⣰⣿⣷⡄⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⣾⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⡟⠁⠀⢀⣼⣿⣿⣿⣿⣆⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⢀⣼⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⠋⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠙⣿⣿⣿⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⣠⣾⣿⣿⣿⣿⣿\n⣿⣿⣿⠿⠛⠁⠀⠀⠀⠙⠻⣿⣿⣿⣿⣿⡿⠟⠋⠀⠀⠀⠈⠛⠻⡿⠟⠛⠁⠀⠀⠈⠉⠉⠉⠉⠀⠀⠀⠀⣀⣴⣾⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣶⣶⣶⣶⣶⣶⣶⣶⣿⣿⣿⣿⣿⣷⣶⣶⣶⣶⣶⣶⣶⣶⣷⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n";
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn xd( pub(crate) async fn xd(ctx: Context<'_>) -> Result<(), Error> {
ctx: Context<'_>,
) -> Result<(), Error> {
ctx.say(XD).await?; ctx.say(XD).await?;
Ok(()) Ok(())
} }

View file

@ -1,12 +1,10 @@
mod commands; mod commands;
use poise::{async_trait, serenity_prelude as serenity, Event}; use poise::{async_trait, serenity_prelude as serenity};
use serenity::client::EventHandler; use serenity::{client::EventHandler, model::id::UserId, FullEvent};
use serenity::model::id::UserId;
use std::collections::HashSet; use std::collections::HashSet;
use std::convert::Into; use std::convert::Into;
use shuttle_secrets::SecretStore;
use shuttle_poise::ShuttlePoise;
struct Data {} // User data, which is stored and accessible in all command invocations struct Data {} // User data, which is stored and accessible in all command invocations
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>; type Context<'a> = poise::Context<'a, Data, Error>;
@ -23,12 +21,8 @@ impl EventHandler for ReadyHandler {
} }
} }
#[shuttle_runtime::main] #[tokio::main]
async fn poise( async fn main() {
#[shuttle_secrets::Secrets]
secret_store: SecretStore
) -> ShuttlePoise<Data, Error> {
let options = poise::FrameworkOptions { let options = poise::FrameworkOptions {
commands: vec![ commands: vec![
commands::lfg::lfg(), commands::lfg::lfg(),
@ -55,39 +49,40 @@ async fn poise(
} }
}) })
}, },
owners: { HashSet::from([UserId(449579075531440128_u64)]) }, owners: { HashSet::from([UserId::new(449579075531440128_u64)]) },
event_handler: |_ctx, event, _framework, _data| { event_handler: |_ctx, event, _framework, _data| {
Box::pin(event_handler(_ctx, event, _framework, _data)) Box::pin(event_handler(_ctx, event, _framework, _data))
}, },
..Default::default() ..Default::default()
}; };
let discord_token = secret_store.get("DISCORD_TOKEN").unwrap();
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(options) .options(options)
.token(discord_token)
.intents(
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT,
)
.setup(move |ctx, _ready, framework| { .setup(move |ctx, _ready, framework| {
Box::pin(async move { Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?; poise::builtins::register_globally(ctx, &framework.options().commands).await?;
Ok(Data {}) Ok(Data {})
}) })
}) })
.build() .build();
.await
.map_err(shuttle_runtime::CustomError::new)?; let token = std::env::var("DISCORD_TOKEN").unwrap();
Ok(framework.into()) let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
let client = serenity::ClientBuilder::new(token, intents)
.framework(framework)
.await;
client.unwrap().start().await.unwrap()
} }
async fn event_handler( async fn event_handler(
_ctx: &serenity::Context, _ctx: &serenity::Context,
event: &Event<'_>, event: &FullEvent,
_framework: poise::FrameworkContext<'_, Data, Error>, _framework: poise::FrameworkContext<'_, Data, Error>,
_data: &Data, _data: &Data,
) -> Result<(), Error> { ) -> Result<(), Error> {
match event { match event {
Event::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);
} }
_ => {} _ => {}