vps ready
This commit is contained in:
parent
6683cef920
commit
edd4c0fd3a
9 changed files with 264 additions and 3277 deletions
3368
Cargo.lock
generated
3368
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,14 +6,10 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
poise = "0.5.6"
|
||||
serenity = { version = "0.12.0", default-features = false, features = ["client", "gateway", "model", "rustls_backend", "utils"]}
|
||||
poise = "0.6.1"
|
||||
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"] }
|
||||
env_logger = "0.10.0"
|
||||
shuttle-secrets = "0.35.2"
|
||||
shuttle-poise = "0.35.2"
|
||||
shuttle-runtime = "0.35.2"
|
||||
anyhow = "1.0.75"
|
||||
tracing = "0.1.40"
|
||||
regex = "1.10.2"
|
||||
cargo-shuttle = { version = "0.35.2" }
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use crate::{Context, Error};
|
||||
use crate::commands::{command_helper, helpstart};
|
||||
use crate::{Context, Error};
|
||||
use std::string::String;
|
||||
|
||||
#[poise::command(slash_command,guild_only)]
|
||||
#[poise::command(slash_command, guild_only)]
|
||||
pub(crate) async fn bots(
|
||||
ctx: Context<'_>,
|
||||
|
||||
#[min = 0_u8]
|
||||
#[description = "default: 0"]
|
||||
bots: u8
|
||||
bots: u8,
|
||||
) -> Result<(), Error> {
|
||||
helpstart::set_bots_available(bots).await;
|
||||
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
use std::time::Duration;
|
||||
use crate::{Context, Error};
|
||||
use serenity::all::CreateAllowedMentions;
|
||||
use std::time::Duration;
|
||||
|
||||
pub(crate) async fn send(
|
||||
ctx: Context<'_>,
|
||||
reply: String
|
||||
) -> Result<(), Error> {
|
||||
pub(crate) async fn send(ctx: Context<'_>, reply: String) -> Result<(), Error> {
|
||||
if let Err(why) = ctx
|
||||
.send(|m| {
|
||||
m.content(reply)
|
||||
.allowed_mentions(|am| am.parse(poise::serenity_prelude::ParseValue::Roles))
|
||||
.send(poise::CreateReply {
|
||||
content: Some(reply),
|
||||
embeds: vec![],
|
||||
attachments: vec![],
|
||||
ephemeral: None,
|
||||
components: None,
|
||||
allowed_mentions: Some(CreateAllowedMentions::new().all_roles(true)),
|
||||
reply: false,
|
||||
__non_exhaustive: (),
|
||||
})
|
||||
.await
|
||||
{
|
||||
|
@ -17,21 +21,22 @@ pub(crate) async fn send(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn cooldown(
|
||||
ctx: &Context,
|
||||
user: u64,
|
||||
global: u64
|
||||
) -> Option<Result<(), Error>> {
|
||||
pub(crate) fn cooldown(ctx: &Context, user: u64, global: u64) -> Option<Result<(), Error>> {
|
||||
let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap();
|
||||
let mut cooldown_durations = poise::CooldownConfig::default();
|
||||
cooldown_durations.user = Some(Duration::from_secs(user));
|
||||
cooldown_durations.global = Some(Duration::from_secs(global));
|
||||
|
||||
match cooldown_tracker.remaining_cooldown_2(*ctx, &cooldown_durations) {
|
||||
Some(remaining) =>
|
||||
Some(Err(format!("Please wait {} seconds", remaining.as_secs()).into())),
|
||||
let cooldown_durations = poise::CooldownConfig {
|
||||
global: Some(Duration::from_secs(global)),
|
||||
user: Some(Duration::from_secs(user)),
|
||||
guild: None,
|
||||
channel: None,
|
||||
member: None,
|
||||
__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 => {
|
||||
cooldown_tracker.start_cooldown(*ctx);
|
||||
cooldown_tracker.start_cooldown((*ctx).cooldown_context());
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,29 @@
|
|||
use crate::{Context, Error};
|
||||
use crate::commands::command_helper;
|
||||
use crate::{Context, Error};
|
||||
|
||||
static mut BOTS_AVAILABLE: u8 = 0;
|
||||
|
||||
#[poise::command(slash_command,guild_only)]
|
||||
#[poise::command(slash_command, guild_only)]
|
||||
pub(crate) async fn helpstart(
|
||||
ctx: Context<'_>,
|
||||
|
||||
#[min = 1_u8]
|
||||
#[max = 3_u8]
|
||||
#[description = "default: 3"]
|
||||
#[rename = "needed"]
|
||||
needed_players: u8
|
||||
#[description = "amount of players in your party, DO NOT include bots"]
|
||||
#[rename = "current"]
|
||||
current_players: u8,
|
||||
) -> Result<(), Error> {
|
||||
let needed_players = 4 - current_players;
|
||||
let bots = unsafe { BOTS_AVAILABLE };
|
||||
|
||||
let reply= if bots >= needed_players {
|
||||
"Bots available. Please use the Zombies Helpstart v2 Bot in the bot-commands channel instead.".to_string()
|
||||
let reply = if bots >= needed_players {
|
||||
"Bots available. Please use <@424767825001971715> in the bot-commands channel instead."
|
||||
.to_string()
|
||||
} else {
|
||||
if let Some(value) = command_helper::cooldown(
|
||||
&ctx,
|
||||
1200,
|
||||
600
|
||||
) {
|
||||
if let Some(value) = command_helper::cooldown(&ctx, 1200, 600) {
|
||||
return value;
|
||||
};
|
||||
format!(
|
||||
"<@&1008075054971621448>\nneed: {}"
|
||||
, needed_players - bots
|
||||
)
|
||||
format!("<@&1008075054971621448>\nneed: {}", needed_players - bots)
|
||||
};
|
||||
|
||||
command_helper::send(ctx, reply).await
|
||||
|
|
|
@ -5,9 +5,10 @@ use crate::commands::lfg::Mode::*;
|
|||
//from main.rs
|
||||
use crate::{Context, Error};
|
||||
//
|
||||
use crate::commands::command_helper;
|
||||
use poise::ChoiceParameter;
|
||||
use serenity::model::mention::Mention;
|
||||
use serenity::model::mention::Mention::Role;
|
||||
use crate::commands::command_helper;
|
||||
|
||||
#[derive(Debug, poise::ChoiceParameter, PartialEq)]
|
||||
pub enum Map {
|
||||
|
@ -38,7 +39,7 @@ pub enum Difficulty {
|
|||
#[name = "R.I.P."]
|
||||
Rip,
|
||||
}
|
||||
#[poise::command(slash_command,guild_only)]
|
||||
#[poise::command(slash_command, guild_only)]
|
||||
pub(crate) async fn lfg(
|
||||
ctx: Context<'_>,
|
||||
|
||||
|
@ -67,32 +68,27 @@ pub(crate) async fn lfg(
|
|||
#[description = "optional extra message"]
|
||||
#[rename = "message"]
|
||||
note: Option<String>,
|
||||
|
||||
) -> Result<(), Error> {
|
||||
if let Some(value) = command_helper::cooldown(
|
||||
&ctx,
|
||||
600,
|
||||
300
|
||||
) {
|
||||
if let Some(value) = command_helper::cooldown(&ctx, 600, 300) {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
let current = current_players.unwrap_or(1);
|
||||
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 ping: Mention;
|
||||
match mode {
|
||||
Casual => match map {
|
||||
DeadEnd => ping = Role(1005837123921915914.into()),
|
||||
BadBlood => ping = Role(1140190470698438666.into()),
|
||||
AlienArcadium => ping = Role(1105917281898336356.into())
|
||||
AlienArcadium => ping = Role(1105917281898336356.into()),
|
||||
},
|
||||
Speedrun => ping = Role(1005836989595144243.into()),
|
||||
Challenge => ping = Role(1005836864680361994.into()),
|
||||
Event => ping = Role(1175116511095050331.into())
|
||||
Event => ping = Role(1175116511095050331.into()),
|
||||
}
|
||||
let diff_name: &str = if map != AlienArcadium {
|
||||
difficulty.unwrap_or(Normal).name()
|
||||
|
@ -100,8 +96,6 @@ pub(crate) async fn lfg(
|
|||
Normal.name()
|
||||
};
|
||||
|
||||
|
||||
|
||||
let mut reply = format!(
|
||||
"{c}/{d} {e} {f} {b}",
|
||||
b = ping,
|
||||
|
@ -121,6 +115,5 @@ pub(crate) async fn lfg(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
command_helper::send(ctx, reply).await
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
pub(crate) mod bots;
|
||||
pub(crate) mod command_helper;
|
||||
pub(crate) mod helpstart;
|
||||
pub(crate) mod lfg;
|
||||
pub(crate) mod xd;
|
||||
pub(crate) mod helpstart;
|
||||
pub(crate) mod command_helper;
|
||||
pub(crate) mod bots;
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn xd(
|
||||
ctx: Context<'_>,
|
||||
) -> Result<(), Error> {
|
||||
pub(crate) async fn xd(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say(XD).await?;
|
||||
Ok(())
|
||||
}
|
41
src/main.rs
41
src/main.rs
|
@ -1,12 +1,10 @@
|
|||
mod commands;
|
||||
|
||||
use poise::{async_trait, serenity_prelude as serenity, Event};
|
||||
use serenity::client::EventHandler;
|
||||
use serenity::model::id::UserId;
|
||||
use poise::{async_trait, serenity_prelude as serenity};
|
||||
use serenity::{client::EventHandler, model::id::UserId, FullEvent};
|
||||
use std::collections::HashSet;
|
||||
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
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
@ -23,12 +21,8 @@ impl EventHandler for ReadyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
#[shuttle_runtime::main]
|
||||
async fn poise(
|
||||
#[shuttle_secrets::Secrets]
|
||||
secret_store: SecretStore
|
||||
) -> ShuttlePoise<Data, Error> {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let options = poise::FrameworkOptions {
|
||||
commands: vec![
|
||||
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| {
|
||||
Box::pin(event_handler(_ctx, event, _framework, _data))
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let discord_token = secret_store.get("DISCORD_TOKEN").unwrap();
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(options)
|
||||
.token(discord_token)
|
||||
.intents(
|
||||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT,
|
||||
)
|
||||
.setup(move |ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {})
|
||||
})
|
||||
})
|
||||
.build()
|
||||
.await
|
||||
.map_err(shuttle_runtime::CustomError::new)?;
|
||||
Ok(framework.into())
|
||||
.build();
|
||||
|
||||
let token = std::env::var("DISCORD_TOKEN").unwrap();
|
||||
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(
|
||||
_ctx: &serenity::Context,
|
||||
event: &Event<'_>,
|
||||
event: &FullEvent,
|
||||
_framework: poise::FrameworkContext<'_, Data, Error>,
|
||||
_data: &Data,
|
||||
) -> Result<(), Error> {
|
||||
match event {
|
||||
Event::Ready { data_about_bot } => {
|
||||
FullEvent::Ready { data_about_bot, .. } => {
|
||||
println!("Logged in as {}", data_about_bot.user.name);
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Add table
Reference in a new issue