reorganized cmds folder structure
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod db;
|
||||||
|
pub mod debug;
|
||||||
|
pub mod generic;
|
||||||
|
pub mod reddit;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod add_server;
|
||||||
|
pub mod main_cmd;
|
||||||
|
pub mod reddit_channel;
|
||||||
|
pub mod wwrps_channel;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
pub mod guild_invite;
|
||||||
|
pub mod leave_guild;
|
||||||
|
pub mod main_cmd;
|
||||||
|
pub mod ping;
|
||||||
|
pub mod reload_cfg;
|
||||||
|
pub mod save;
|
||||||
|
pub mod stop;
|
||||||
|
pub mod view_guilds;
|
||||||
|
pub mod whoami;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod eight_ball;
|
||||||
|
pub mod embed;
|
||||||
|
pub mod help;
|
||||||
|
pub mod send;
|
||||||
|
pub mod wwrps;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
pub mod add;
|
||||||
|
pub mod approve;
|
||||||
|
pub mod generic_fns;
|
||||||
|
pub mod get;
|
||||||
|
pub mod remove;
|
||||||
|
pub mod shorturl;
|
||||||
|
pub mod top;
|
||||||
|
pub mod update;
|
||||||
|
pub mod vote;
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
use poise::serenity_prelude::{CreateInvite, GuildId};
|
|
||||||
|
|
||||||
use crate::{Context, Error, lang, messages::send_msg};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>, guild_id: u64) -> Result<(), Error> {
|
|
||||||
let id = GuildId::from(guild_id);
|
|
||||||
let guild = id.to_partial_guild(ctx.http()).await?;
|
|
||||||
|
|
||||||
if !ctx.serenity_context().cache.guilds().contains(&id) {
|
|
||||||
send_msg(ctx, lang!("dc_msg_not_in_guild"), true, true).await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let ch = guild.channels(ctx.http()).await?
|
|
||||||
.values()
|
|
||||||
.find(|c| c.is_text_based())
|
|
||||||
.cloned();
|
|
||||||
|
|
||||||
if let Some(channel) = ch {
|
|
||||||
let bot_member = &guild.member(ctx.http(), ctx.framework().bot_id).await?;
|
|
||||||
let perms = guild.user_permissions_in(&channel, bot_member);
|
|
||||||
|
|
||||||
if !perms.create_instant_invite() {
|
|
||||||
send_msg(ctx, lang!("dc_msg_no_perms", "CreateInvite"), true, true).await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let inv_builder = CreateInvite::new().max_age(0).max_uses(0);
|
|
||||||
let inv = channel.id.create_invite(ctx.http(), inv_builder).await?;
|
|
||||||
send_msg(ctx, inv.url(), true, true).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
use poise::serenity_prelude::GuildId;
|
|
||||||
|
|
||||||
use crate::{Context, Error, lang, messages::send_msg};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>, guild_id: u64) -> Result<(), Error> {
|
|
||||||
let id = GuildId::from(guild_id);
|
|
||||||
let guild = id.to_partial_guild(ctx.http()).await?;
|
|
||||||
|
|
||||||
if !ctx.serenity_context().cache.guilds().contains(&id) {
|
|
||||||
send_msg(ctx, lang!("dc_msg_not_in_guild"), true, true).await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
guild.leave(ctx.http()).await?;
|
|
||||||
send_msg(ctx, lang!("success"), true, true).await;
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
use crate::{Context, Error, debug_cmds::{guild_invite, leave_guild, ping, save, stop, view_guilds, whoami}};
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(poise::ChoiceParameter, PartialEq)]
|
|
||||||
pub enum Subcommands {
|
|
||||||
GuildInvite,
|
|
||||||
LeaveGuild,
|
|
||||||
Ping,
|
|
||||||
//ReloadCfg,
|
|
||||||
Save,
|
|
||||||
Stop,
|
|
||||||
ViewGuilds,
|
|
||||||
WhoAmI
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
prefix_command,
|
|
||||||
category = "owner",
|
|
||||||
rename = "debug",
|
|
||||||
owners_only,
|
|
||||||
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
|
|
||||||
)]
|
|
||||||
/// Various debug utilities
|
|
||||||
pub async fn cmd(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
#[description = "Subcommand"] subcommand: Subcommands,
|
|
||||||
string_arg: Option<String>,
|
|
||||||
u64_arg: Option<String>
|
|
||||||
) -> Result<(), Error>
|
|
||||||
{
|
|
||||||
let u64_arg_u: u64 = u64_arg.unwrap_or("0".to_string()).as_str().parse()?;
|
|
||||||
|
|
||||||
match subcommand {
|
|
||||||
Subcommands::GuildInvite => guild_invite::cmd(ctx, u64_arg_u).await?,
|
|
||||||
Subcommands::LeaveGuild => leave_guild::cmd(ctx, u64_arg_u).await?,
|
|
||||||
Subcommands::Ping => ping::cmd(ctx).await?,
|
|
||||||
//Subcommands::ReloadCfg => reload_cfg::cmd(ctx).await?,
|
|
||||||
Subcommands::Save => save::cmd(ctx).await?,
|
|
||||||
Subcommands::Stop => stop::cmd(ctx, string_arg).await?,
|
|
||||||
Subcommands::ViewGuilds => view_guilds::cmd(ctx).await?,
|
|
||||||
Subcommands::WhoAmI => whoami::cmd(ctx).await?,
|
|
||||||
//_ => return Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
use crate::{messages::send_msg, Context, Error};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
send_msg(ctx, "Pong".to_string(), true, true).await;
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/*use crate::{Context, Error, data::{self, get_toml_mutex, read_cfg_data}, lang, messages::send_msg};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
let r = read_cfg_data(ctx.data(), false).await;
|
|
||||||
let d = get_toml_mutex(&ctx.data().cfg).await.unwrap();
|
|
||||||
|
|
||||||
if r.is_none() { return Ok(()); }
|
|
||||||
|
|
||||||
update_cfg(ctx).await;
|
|
||||||
|
|
||||||
if r.unwrap()["value"].as_bool().unwrap() {
|
|
||||||
send_msg(
|
|
||||||
ctx,
|
|
||||||
lang!("dc_msg_reload_cfg_success", toml::to_string_pretty(&d).unwrap()),
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
).await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
send_msg(ctx, lang!("dc_msg_reload_cfg_python_fail"), true, true).await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async fn update_cfg(ctx: Context<'_>) {
|
|
||||||
let data_binding = get_toml_mutex(&ctx.data().cfg).await.unwrap();
|
|
||||||
let lang_cfg = data_binding["general"]["lang"].as_str().unwrap();
|
|
||||||
data::load_lang_data(lang_cfg.to_string());
|
|
||||||
|
|
||||||
set_status(data_binding, ctx).await;
|
|
||||||
}*/
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
use crate::{Context, Error, db::{discord, reddit}, lang, messages::{edit_reply, send_msg}};
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
let msg = send_msg(ctx, lang!("dc_msg_owner_data_save"), true, true).await.unwrap();
|
|
||||||
|
|
||||||
discord::write_data(ctx.data()).await;
|
|
||||||
reddit ::write_data().await;
|
|
||||||
|
|
||||||
edit_reply(ctx, msg, lang!("dc_msg_owner_data_save_complete")).await;
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
use std::process;
|
|
||||||
|
|
||||||
use poise::serenity_prelude::OnlineStatus;
|
|
||||||
|
|
||||||
use crate::{db::{discord, reddit}, lang, messages::{edit_reply, send_msg}, websocket::send_cmd_json, Context, Error};
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>, confirmation: Option<String>) -> Result<(), Error> {
|
|
||||||
let stop_confirm = "i want to stop the bot now".replace(" ", "");
|
|
||||||
let confirm_formatted = confirmation.unwrap_or_default().to_lowercase().replace(" ", "");
|
|
||||||
let should_stop = ctx.data().args.dev || confirm_formatted == stop_confirm;
|
|
||||||
|
|
||||||
if should_stop {
|
|
||||||
let msg = send_msg(ctx, lang!("dc_msg_owner_data_save"), true, true).await.unwrap();
|
|
||||||
discord::write_data(ctx.data()).await;
|
|
||||||
reddit ::write_data().await;
|
|
||||||
send_cmd_json("stop_praw", None, true).await;
|
|
||||||
|
|
||||||
let complete = format!(
|
|
||||||
"{}\n{}",
|
|
||||||
lang!("dc_msg_owner_data_save_complete"),
|
|
||||||
lang!("dc_msg_owner_shutdown")
|
|
||||||
);
|
|
||||||
|
|
||||||
edit_reply(ctx, msg, complete).await;
|
|
||||||
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
|
||||||
ctx.framework().shard_manager.shutdown_all().await;
|
|
||||||
|
|
||||||
process::exit(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
send_msg(ctx, lang!("dc_msg_owner_shutdown_failed_confirmation"), true, true).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
use crate::{Context, Error, messages::send_msg};
|
|
||||||
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
let guilds = ctx.cache().guilds();
|
|
||||||
let mut msgs: Vec<Vec<String>> = vec![vec![]];
|
|
||||||
let mut char_count: usize = 0;
|
|
||||||
let mut msg_idx: usize = 0;
|
|
||||||
|
|
||||||
for g in guilds {
|
|
||||||
let name = g.name(ctx.cache()).unwrap_or("[unnamed]".to_string());
|
|
||||||
let id = g.get();
|
|
||||||
|
|
||||||
let msg = format!("**[{}]** {}", id, name);
|
|
||||||
char_count += msg.len();
|
|
||||||
|
|
||||||
if char_count >= 2000 {
|
|
||||||
msgs.push(Vec::new());
|
|
||||||
msg_idx += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
msgs[msg_idx].push(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
for msg in msgs
|
|
||||||
{ send_msg(ctx, msg.join("\n"), true, true).await; }
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
use crate::{lang, messages::send_msg, Context, Error};
|
|
||||||
|
|
||||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
let data = ctx.data();
|
|
||||||
let uid: u64 = ctx.author().id.into();
|
|
||||||
|
|
||||||
let is_owner = data.owners .contains(&uid);
|
|
||||||
let is_bk_mod = data.bk_mods.contains(&uid);
|
|
||||||
|
|
||||||
send_msg(ctx, lang!("dc_msg_whoami", is_owner, is_bk_mod), true, true).await;
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
+1
-1
@@ -2,7 +2,7 @@ use crate::db::generic::{get_json_mutex, get_toml_mutex};
|
|||||||
use crate::db::reddit::update_data;
|
use crate::db::reddit::update_data;
|
||||||
use crate::r#gen::set_status;
|
use crate::r#gen::set_status;
|
||||||
use crate::messages::{make_post_embed, make_removed_embed, EmbedOptions};
|
use crate::messages::{make_post_embed, make_removed_embed, EmbedOptions};
|
||||||
use crate::re_cmds::generic_fns::{is_bk_mod, is_bk_mod_serenity, serenity_edit_msg_embed, serenity_send_msg};
|
use crate::cmds::reddit::generic_fns::{is_bk_mod, is_bk_mod_serenity, serenity_edit_msg_embed, serenity_send_msg};
|
||||||
use crate::websocket::send_cmd_json;
|
use crate::websocket::send_cmd_json;
|
||||||
use crate::{Data, Error, lang, rs_println};
|
use crate::{Data, Error, lang, rs_println};
|
||||||
use crate::db::reddit::POSTS_KEY;
|
use crate::db::reddit::POSTS_KEY;
|
||||||
|
|||||||
+17
-17
@@ -6,11 +6,11 @@ use poise::serenity_prelude::Client;
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use crate::cmds::wwrps::RPSGame;
|
use crate::cmds::generic::wwrps::RPSGame;
|
||||||
use crate::db::{cfg, discord, reddit};
|
use crate::db::{cfg, discord, reddit};
|
||||||
use crate::db::generic::get_toml_mutex;
|
use crate::db::generic::get_toml_mutex;
|
||||||
use crate::lang::Lang;
|
use crate::lang::Lang;
|
||||||
use crate::{Args, Cmd, Data, cmds, db_cmds, debug_cmds, events, re_cmds, rs_println};
|
use crate::{Args, Cmd, Data, cmds, events, rs_println};
|
||||||
|
|
||||||
|
|
||||||
pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
|
pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
|
||||||
@@ -91,24 +91,24 @@ pub async fn gen_bot(data: Data, args: Args) -> Client {
|
|||||||
async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
|
async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
|
||||||
let mut cmds = vec![
|
let mut cmds = vec![
|
||||||
// GENERIC
|
// GENERIC
|
||||||
cmds::help::cmd(),
|
cmds::generic::help::cmd(),
|
||||||
cmds::eight_ball::cmd(),
|
cmds::generic::eight_ball::cmd(),
|
||||||
cmds::wwrps::cmd(),
|
cmds::generic::wwrps::cmd(),
|
||||||
// REDDIT
|
// REDDIT
|
||||||
re_cmds::add::cmd(),
|
cmds::reddit::add::cmd(),
|
||||||
re_cmds::approve::cmd(),
|
cmds::reddit::approve::cmd(),
|
||||||
re_cmds::get::cmd(),
|
cmds::reddit::get::cmd(),
|
||||||
re_cmds::remove::cmd(),
|
cmds::reddit::remove::cmd(),
|
||||||
re_cmds::top::cmd(),
|
cmds::reddit::top::cmd(),
|
||||||
re_cmds::update::cmd(),
|
cmds::reddit::update::cmd(),
|
||||||
re_cmds::vote::cmd(),
|
cmds::reddit::vote::cmd(),
|
||||||
re_cmds::shorturl::cmd(),
|
cmds::reddit::shorturl::cmd(),
|
||||||
// OWNER
|
// OWNER
|
||||||
cmds::embed::cmd(),
|
cmds::generic::embed::cmd(),
|
||||||
cmds::send::cmd(),
|
cmds::generic::send::cmd(),
|
||||||
debug_cmds::main_cmd::cmd(),
|
cmds::debug::main_cmd::cmd(),
|
||||||
// DATABASE
|
// DATABASE
|
||||||
db_cmds::main_cmd::cmd()
|
cmds::db::main_cmd::cmd()
|
||||||
];
|
];
|
||||||
let cfg = get_toml_mutex(&data.cfg).await.unwrap();
|
let cfg = get_toml_mutex(&data.cfg).await.unwrap();
|
||||||
|
|
||||||
|
|||||||
+3
-36
@@ -2,47 +2,14 @@
|
|||||||
#![allow(clippy::needless_return)]
|
#![allow(clippy::needless_return)]
|
||||||
#![allow(static_mut_refs)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
mod cmds {
|
|
||||||
pub mod eight_ball;
|
|
||||||
pub mod embed;
|
|
||||||
pub mod help;
|
|
||||||
pub mod send;
|
|
||||||
pub mod wwrps;
|
|
||||||
}
|
|
||||||
mod re_cmds {
|
|
||||||
pub mod add;
|
|
||||||
pub mod approve;
|
|
||||||
pub mod generic_fns;
|
|
||||||
pub mod get;
|
|
||||||
pub mod remove;
|
|
||||||
pub mod shorturl;
|
|
||||||
pub mod top;
|
|
||||||
pub mod update;
|
|
||||||
pub mod vote;
|
|
||||||
}
|
|
||||||
mod debug_cmds {
|
|
||||||
pub mod guild_invite;
|
|
||||||
pub mod leave_guild;
|
|
||||||
pub mod main_cmd;
|
|
||||||
pub mod ping;
|
|
||||||
pub mod reload_cfg;
|
|
||||||
pub mod save;
|
|
||||||
pub mod stop;
|
|
||||||
pub mod view_guilds;
|
|
||||||
pub mod whoami;
|
|
||||||
}
|
|
||||||
mod db_cmds {
|
|
||||||
pub mod add_server;
|
|
||||||
pub mod reddit_channel;
|
|
||||||
pub mod main_cmd;
|
|
||||||
pub mod wwrps_channel;
|
|
||||||
}
|
|
||||||
mod events;
|
mod events;
|
||||||
mod messages;
|
mod messages;
|
||||||
mod python;
|
mod python;
|
||||||
mod macros;
|
mod macros;
|
||||||
#[allow(unknown_lints)]
|
#[allow(unknown_lints)]
|
||||||
mod websocket;
|
mod websocket;
|
||||||
|
mod cmds;
|
||||||
mod db;
|
mod db;
|
||||||
mod schedule;
|
mod schedule;
|
||||||
mod gen;
|
mod gen;
|
||||||
@@ -65,7 +32,7 @@ use tokio::runtime::Runtime;
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use websocket::send_cmd_json;
|
use websocket::send_cmd_json;
|
||||||
|
|
||||||
use crate::cmds::wwrps::RPSGame;
|
use crate::cmds::generic::wwrps::RPSGame;
|
||||||
use crate::db::generic::get_toml_mutex;
|
use crate::db::generic::get_toml_mutex;
|
||||||
use crate::lang::Lang;
|
use crate::lang::Lang;
|
||||||
use crate::schedule::Schedule;
|
use crate::schedule::Schedule;
|
||||||
|
|||||||
Reference in New Issue
Block a user