finished debug subcommands
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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(());
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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,4 +1,4 @@
|
||||
use crate::{Context, Error, debug_cmds::{ping, reload_cfg, stop, whoami}};
|
||||
use crate::{Context, Error, debug_cmds::{guild_invite, leave_guild, ping, reload_cfg, stop, view_guilds, whoami}};
|
||||
|
||||
|
||||
#[derive(poise::ChoiceParameter, PartialEq)]
|
||||
@@ -24,15 +24,21 @@ pub enum Subcommands {
|
||||
pub async fn cmd(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Subcommand"] subcommand: Subcommands,
|
||||
string_arg: Option<String>
|
||||
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::Ping => ping::cmd(ctx).await?,
|
||||
Subcommands::ReloadCfg => reload_cfg::cmd(ctx).await?,
|
||||
Subcommands::Stop => stop::cmd(ctx, string_arg).await?,
|
||||
Subcommands::WhoAmI => whoami::cmd(ctx).await?,
|
||||
_ => return Ok(())
|
||||
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::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,7 +1,7 @@
|
||||
use crate::{messages::send_msg, Context, Error};
|
||||
|
||||
|
||||
pub async fn cmd(ctx: Context<'_>,) -> Result<(), Error> {
|
||||
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
|
||||
send_msg(ctx, "Pong".to_string(), true, true).await;
|
||||
|
||||
return Ok(());
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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(());
|
||||
}
|
||||
Reference in New Issue
Block a user