i added too much
This commit is contained in:
@@ -8,4 +8,5 @@ edition = "2021"
|
||||
[dependencies]
|
||||
poise = "0.6.1"
|
||||
rand = "0.9.0"
|
||||
serde_json = "1.0.138"
|
||||
tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"my name",
|
||||
"is not jeff."
|
||||
]
|
||||
+74
-10
@@ -1,16 +1,16 @@
|
||||
use crate::{send_embed, send_msg, Context, EmbedOptions, Error};
|
||||
use crate::{send_embed, send_msg, edit_msg, Context, EmbedOptions, Error};
|
||||
|
||||
use poise::serenity_prelude::{OnlineStatus, Timestamp};
|
||||
use poise::serenity_prelude::{GetMessages, OnlineStatus, Timestamp};
|
||||
use rand::{seq::IteratorRandom, Rng};
|
||||
|
||||
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn ping(
|
||||
ctx: Context<'_>,
|
||||
#[description = "The text to echo back"] text: Option<String>,
|
||||
#[description = "The text to echo back."] text: Option<String>,
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
send_msg(ctx, text.unwrap_or_else(|| "Pong".to_string()), true).await?;
|
||||
send_msg(ctx, text.unwrap_or_else(|| "Pong".to_string()), true, true).await;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@@ -19,7 +19,7 @@ pub async fn ping(
|
||||
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR")]
|
||||
pub async fn stop(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Type \"i want to stop the bot now\" to confirm"] confirmation: Option<String>,
|
||||
#[description = "Type \"i want to stop the bot now\" to confirm."] confirmation: Option<String>,
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
let dev_enabled = ctx.data().dev;
|
||||
@@ -27,12 +27,12 @@ pub async fn stop(
|
||||
|| confirmation.unwrap_or_else(|| "".to_string()).to_lowercase() == "i want to stop the bot now";
|
||||
|
||||
if should_stop {
|
||||
send_msg(ctx, "Shutting down...".to_string(), true).await?;
|
||||
send_msg(ctx, "Shutting down...".to_string(), true, true).await;
|
||||
ctx.serenity_context().set_presence(None, OnlineStatus::Invisible);
|
||||
ctx.framework().shard_manager.shutdown_all().await;
|
||||
}
|
||||
else {
|
||||
send_msg(ctx, "Failed to shut down.".to_string(), true).await?;
|
||||
send_msg(ctx, "Failed to shut down.".to_string(), true, true).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
@@ -51,9 +51,12 @@ pub async fn embed(
|
||||
#[description = "Color of side strip."] color: Option<u32>,
|
||||
#[description = "A URL the title is bound to."] url: Option<String>,
|
||||
#[description = "Timestamp at bottom (best to leave empty)."] timestamp: Option<Timestamp>,
|
||||
#[description = "Empheral (only visible to you)"] empheral: Option<bool>
|
||||
#[description = "Empheral (only visible to you)."] empheral: Option<bool>,
|
||||
#[description = "Shows \"used {Command}\" reply text."] reply: Option<bool>
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
let reply_unwrap = reply.unwrap_or_else(|| false);
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
EmbedOptions {
|
||||
@@ -63,8 +66,13 @@ pub async fn embed(
|
||||
url,
|
||||
ts: timestamp,
|
||||
empheral: empheral.unwrap_or_else(|| false)
|
||||
},
|
||||
reply_unwrap
|
||||
).await;
|
||||
|
||||
if !reply_unwrap {
|
||||
send_msg(ctx, "Mandatory success response.".to_string(), true, true).await;
|
||||
}
|
||||
).await?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@@ -83,8 +91,64 @@ pub async fn eight_ball(
|
||||
send_msg(
|
||||
ctx,
|
||||
format!("Q: {}\nA: {}", question, rand_item.unwrap()),
|
||||
true,
|
||||
true
|
||||
).await?;
|
||||
).await;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
default_member_permissions = "ADMINISTRATOR"
|
||||
)]
|
||||
pub async fn write_json(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Delete all messages sent by the bot in the selected channel."] remove_all: Option<bool>,
|
||||
#[description = "Includes \"Use '/rule {rule}' to view rules individually\" preset message"] include_rule_command: Option<bool>,
|
||||
#[description = "JSON (empty is preset file)"] json: Option<String>
|
||||
) -> Result<(), Error>
|
||||
{
|
||||
let rm_all = remove_all.unwrap_or_else(|| false);
|
||||
let include_cmd = include_rule_command.unwrap_or_else(|| false);
|
||||
|
||||
if rm_all {
|
||||
let progress = send_msg(ctx, "Deleting all messages in channel...".to_string(), true, true).await;
|
||||
|
||||
let builder = GetMessages::new().limit(100);
|
||||
let msgs = ctx.channel_id().messages(ctx.http(), builder).await?;
|
||||
|
||||
for msg in msgs {
|
||||
if msg.author.id == ctx.framework().bot_id {
|
||||
msg.delete(ctx.http()).await?;
|
||||
}
|
||||
}
|
||||
|
||||
edit_msg(ctx, progress.unwrap(), "Deleting all messages in channel... Done!".to_string()).await;
|
||||
}
|
||||
|
||||
let json_str = json.unwrap_or_else(||
|
||||
std::fs::read_to_string("./data/write_json.json")
|
||||
.expect("No JSON preset file exists.")
|
||||
);
|
||||
|
||||
let json_json: serde_json::Value = serde_json::from_str(&json_str).expect("JSON was improperly formatted");
|
||||
if !json_json.is_array() {
|
||||
send_msg(ctx, "JSON is not an array of strings".to_string(), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for i in json_json.as_array().unwrap() {
|
||||
if !i.is_string() { continue; }
|
||||
let i_str = i.to_string();
|
||||
send_msg(ctx, i_str[1..i_str.len() - 1].to_string(), false, false).await;
|
||||
}
|
||||
|
||||
if include_cmd {
|
||||
send_msg(ctx, "Use /rules thank you".to_string(), false, false).await;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
+43
-14
@@ -1,7 +1,7 @@
|
||||
mod cmds;
|
||||
mod events;
|
||||
|
||||
use poise::CreateReply;
|
||||
use poise::{serenity_prelude::CreateMessage, CreateReply, ReplyHandle};
|
||||
use std::env;
|
||||
|
||||
use poise::serenity_prelude::{self as serenity, Color, CreateEmbed, Timestamp};
|
||||
@@ -66,7 +66,8 @@ async fn main() {
|
||||
cmds::ping(),
|
||||
cmds::embed(),
|
||||
cmds::stop(),
|
||||
cmds::eight_ball()
|
||||
cmds::eight_ball(),
|
||||
cmds::write_json()
|
||||
],
|
||||
event_handler: events::event_handler,
|
||||
..Default::default()
|
||||
@@ -97,40 +98,68 @@ fn none_to_empty(string: Option<String>) -> String {
|
||||
async fn send_msg(
|
||||
ctx: Context<'_>,
|
||||
t: String,
|
||||
empheral: bool
|
||||
) -> Result<(), Error>
|
||||
empheral: bool,
|
||||
reply: bool
|
||||
) -> Option<ReplyHandle<'_>>
|
||||
{
|
||||
if reply {
|
||||
let r = CreateReply {
|
||||
content: Some(t),
|
||||
ephemeral: Some(empheral),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
ctx.send(r).await?;
|
||||
|
||||
return Ok(());
|
||||
let msg = ctx.send(r).await;
|
||||
return Some(msg.unwrap());
|
||||
}
|
||||
else {
|
||||
let _ = ctx.channel_id().say(ctx.http(), t).await;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async fn send_embed(
|
||||
ctx: Context<'_>,
|
||||
options: EmbedOptions,
|
||||
) -> Result<(), Error>
|
||||
reply: bool
|
||||
) -> Option<ReplyHandle<'_>>
|
||||
{
|
||||
let embed = CreateEmbed::new()
|
||||
let mut embed = CreateEmbed::new()
|
||||
.title (none_to_empty(options.title))
|
||||
.description(options.desc)
|
||||
.colour (Color::new(options.col.unwrap_or_else(|| 5793266)))
|
||||
.url (none_to_empty(options.url))
|
||||
.timestamp (options.ts.unwrap_or_else(|| Timestamp::now()));
|
||||
.url (none_to_empty(options.url));
|
||||
|
||||
if options.ts.is_some() { embed = embed.timestamp(options.ts.unwrap()); }
|
||||
|
||||
if reply {
|
||||
let r = CreateReply {
|
||||
embeds: vec![embed],
|
||||
ephemeral: Some(options.empheral),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
ctx.send(r).await?;
|
||||
|
||||
return Ok(());
|
||||
let msg = ctx.send(r).await;
|
||||
return Some(msg.unwrap());
|
||||
}
|
||||
else {
|
||||
let r = CreateMessage::new().embeds(vec![embed]);
|
||||
let _ = ctx.channel_id().send_message(ctx.http(), r).await;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async fn edit_msg(
|
||||
ctx: Context<'_>,
|
||||
msg: ReplyHandle<'_>,
|
||||
new_text: String
|
||||
) {
|
||||
let r = CreateReply {
|
||||
content: Some(new_text),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let _ = msg.edit(ctx, r).await;
|
||||
}
|
||||
Reference in New Issue
Block a user