Many fixes and tweaks
* Fix tags (again?) * Make tag names more consistent * Remove prefix commands (not implemented well and not worth fixing) * Allow '-'s in tags * Fix /joke * Fix /members * Fix intel_hd issue match * Fix log analysis reply * Clearer log analysis messages It's weird to say the process failed when no issues were found. * Clippy * Final doc cleanup * Fix link expanding * Fix duplicate event filtering The other code simply does not work. ChannelId does have a method to grab members but I'm not sure whether it would work either. * Remove message resolution It's surprisingly hard to create an bug-free implementation. * Fix pluralkit detection * simplify tag codegen * commands: improve error handling in members unwrap() bad!!!11!! * events: use debug logs for pk checks * Revert "Remove message resolution" This reverts commit 0d9f224a81917212adafdeb2213f3cc11b44cf88. * Bring back prefix commands with "." (it's easier to type) * Add help * Fix messsage resolution * utils: factor out message resolution * Improve tag message * Disable VC support for message resolution for now * Improve prefix command usage Update on edit, display additional tip with wrong usage. * Check invoke_on_edit to display tip * Add defer in commands which make http requests * Apply tag sorting to slash commands too * handlers::error: `+=` -> `writeln!` * handlers::event: ignore own new messages * help: remove unneeded format! * optimize for size in release builds * nix: cleanup deployment expressions * nix: use treefmt * nix: update flake.lock Flake lock file updates: • Updated input 'fenix': 'github:nix-community/fenix/eb683549b7d76b12d1a009f888b91b70ed34485f' (2024-01-27) → 'github:nix-community/fenix/c53bb4a32f2fce7acf4e8e160a54779c4460ffdb' (2024-03-17) • Updated input 'fenix/rust-analyzer-src': 'github:rust-lang/rust-analyzer/596e5c77cf5b2b660b3ac2ce732fa0596c246d9b' (2024-01-26) → 'github:rust-lang/rust-analyzer/5ecace48f693afaa6adf8cb23086b651db3aec96' (2024-03-16) • Updated input 'nixpkgs': 'github:nixos/nixpkgs/4fddc9be4eaf195d631333908f2a454b03628ee5' (2024-01-25) → 'github:nixos/nixpkgs/34ad8c9f29a18b4dd97a9ad40ceb16954f24afe7' (2024-03-17) • Updated input 'pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/f56597d53fd174f796b5a7d3ee0b494f9e2285cc' (2024-01-20) → 'github:cachix/pre-commit-hooks.nix/5df5a70ad7575f6601d91f0efec95dd9bc619431' (2024-02-15) • Updated input 'procfile-nix': 'github:getchoo/procfile-nix/31a33e4264e5c6214844993c5b508fb3500ef5cd' (2024-01-27) → 'github:getchoo/procfile-nix/7a0ab379a4ab71c9deccaca9fb463e9aaea363d8' (2024-03-14) --------- Co-authored-by: seth <getchoo@tuta.io>
This commit is contained in:
parent
1ea08671fb
commit
9d0c022c68
38 changed files with 492 additions and 296 deletions
23
src/commands/general/help.rs
Normal file
23
src/commands/general/help.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use eyre::Result;
|
||||
use poise::{builtins, samples::HelpConfiguration};
|
||||
|
||||
use crate::Context;
|
||||
|
||||
/// View the help menu
|
||||
#[poise::command(slash_command, prefix_command, track_edits = true)]
|
||||
pub async fn help(
|
||||
ctx: Context<'_>,
|
||||
#[description = "provide information about a specific command"] command: Option<String>,
|
||||
) -> Result<()> {
|
||||
builtins::help(
|
||||
ctx,
|
||||
command.as_deref(),
|
||||
HelpConfiguration {
|
||||
extra_text_at_bottom: "Use /help for more information about a specific command!",
|
||||
..HelpConfiguration::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -5,11 +5,14 @@ use eyre::Result;
|
|||
use log::trace;
|
||||
|
||||
/// It's a joke
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
#[poise::command(slash_command, prefix_command, track_edits = true)]
|
||||
pub async fn joke(ctx: Context<'_>) -> Result<()> {
|
||||
trace!("Running joke command");
|
||||
|
||||
ctx.defer().await?;
|
||||
|
||||
let joke = dadjoke::get_joke().await?;
|
||||
|
||||
ctx.reply(joke).await?;
|
||||
ctx.say(joke).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,26 +1,34 @@
|
|||
use crate::{consts, Context};
|
||||
|
||||
use eyre::{OptionExt, Result};
|
||||
use eyre::{eyre, Context as _, OptionExt, Result};
|
||||
use log::trace;
|
||||
use poise::serenity_prelude::CreateEmbed;
|
||||
use poise::CreateReply;
|
||||
|
||||
/// Returns the number of members in the server
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
#[poise::command(slash_command, prefix_command, guild_only = true, track_edits = true)]
|
||||
pub async fn members(ctx: Context<'_>) -> Result<()> {
|
||||
trace!("Running members command");
|
||||
let guild = ctx.guild().ok_or_eyre("Couldn't fetch guild!")?.to_owned();
|
||||
|
||||
let count = guild.member_count;
|
||||
let online = if let Some(count) = guild.approximate_presence_count {
|
||||
count.to_string()
|
||||
} else {
|
||||
"Undefined".to_string()
|
||||
};
|
||||
ctx.defer().await?;
|
||||
|
||||
let guild_id = ctx.guild_id().ok_or_eyre("Couldn't get guild ID!")?;
|
||||
let guild = ctx
|
||||
.http()
|
||||
.get_guild_with_counts(guild_id)
|
||||
.await
|
||||
.wrap_err_with(|| format!("Couldn't fetch guild {guild_id} with counts!"))?;
|
||||
|
||||
let member_count = guild
|
||||
.approximate_member_count
|
||||
.ok_or_else(|| eyre!("Couldn't get member count for guild {guild_id}!"))?;
|
||||
let online_count = guild
|
||||
.approximate_presence_count
|
||||
.ok_or_else(|| eyre!("Couldn't get online count for guild {guild_id}!"))?;
|
||||
|
||||
let embed = CreateEmbed::new()
|
||||
.title(format!("{count} total members!"))
|
||||
.description(format!("{online} online members"))
|
||||
.title(format!("{member_count} total members!",))
|
||||
.description(format!("{online_count} online members",))
|
||||
.color(consts::COLORS["blue"]);
|
||||
let reply = CreateReply::default().embed(embed);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
mod help;
|
||||
mod joke;
|
||||
mod members;
|
||||
mod ping;
|
||||
|
@ -6,6 +7,7 @@ mod say;
|
|||
mod stars;
|
||||
mod tag;
|
||||
|
||||
pub use help::help;
|
||||
pub use joke::joke;
|
||||
pub use members::members;
|
||||
pub use ping::ping;
|
||||
|
|
|
@ -4,9 +4,9 @@ use eyre::Result;
|
|||
use log::trace;
|
||||
|
||||
/// Replies with pong!
|
||||
#[poise::command(slash_command, prefix_command, ephemeral)]
|
||||
#[poise::command(slash_command, prefix_command, track_edits = true, ephemeral)]
|
||||
pub async fn ping(ctx: Context<'_>) -> Result<()> {
|
||||
trace!("Running ping command!");
|
||||
ctx.reply("Pong!").await?;
|
||||
ctx.say("Pong!").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -7,12 +7,15 @@ use poise::serenity_prelude::{CreateEmbed, CreateEmbedFooter};
|
|||
use poise::CreateReply;
|
||||
|
||||
/// Gets a Rory photo!
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
#[poise::command(slash_command, prefix_command, track_edits = true)]
|
||||
pub async fn rory(
|
||||
ctx: Context<'_>,
|
||||
#[description = "specify a Rory ID"] id: Option<u64>,
|
||||
) -> Result<()> {
|
||||
trace!("Running rory command");
|
||||
|
||||
ctx.defer().await?;
|
||||
|
||||
let rory = rory::get(id).await?;
|
||||
|
||||
let embed = {
|
||||
|
|
|
@ -9,18 +9,30 @@ use poise::serenity_prelude::{CreateEmbed, CreateEmbedAuthor, CreateMessage};
|
|||
prefix_command,
|
||||
ephemeral,
|
||||
default_member_permissions = "MODERATE_MEMBERS",
|
||||
required_permissions = "MODERATE_MEMBERS"
|
||||
required_permissions = "MODERATE_MEMBERS",
|
||||
guild_only = true
|
||||
)]
|
||||
pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: String) -> Result<()> {
|
||||
pub async fn say(
|
||||
ctx: Context<'_>,
|
||||
#[description = "the message content"] content: String,
|
||||
) -> Result<()> {
|
||||
let guild = ctx.guild().ok_or_eyre("Couldn't get guild!")?.to_owned();
|
||||
let channel = ctx
|
||||
.guild_channel()
|
||||
.await
|
||||
.ok_or_eyre("Couldn't get channel!")?;
|
||||
|
||||
if let Context::Prefix(prefix) = ctx {
|
||||
// ignore error, we might not have perm
|
||||
let _ = prefix.msg.delete(ctx).await;
|
||||
}
|
||||
|
||||
ctx.defer_ephemeral().await?;
|
||||
channel.say(ctx, &content).await?;
|
||||
ctx.say("I said what you said!").await?;
|
||||
|
||||
if let Context::Application(_) = ctx {
|
||||
ctx.say("I said what you said!").await?;
|
||||
}
|
||||
|
||||
if let Some(channel_id) = ctx.data().config.discord.channels().say_log_channel_id() {
|
||||
let log_channel = guild
|
||||
|
@ -29,8 +41,11 @@ pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: Str
|
|||
.find(|c| c.0 == &channel_id)
|
||||
.ok_or_eyre("Couldn't get log channel from guild!")?;
|
||||
|
||||
let author = CreateEmbedAuthor::new(ctx.author().tag())
|
||||
.icon_url(ctx.author().avatar_url().unwrap_or("Undefined".to_string()));
|
||||
let author = CreateEmbedAuthor::new(ctx.author().tag()).icon_url(
|
||||
ctx.author()
|
||||
.avatar_url()
|
||||
.unwrap_or_else(|| ctx.author().default_avatar_url()),
|
||||
);
|
||||
|
||||
let embed = CreateEmbed::default()
|
||||
.title("Say command used!")
|
||||
|
|
|
@ -6,10 +6,12 @@ use poise::serenity_prelude::CreateEmbed;
|
|||
use poise::CreateReply;
|
||||
|
||||
/// Returns GitHub stargazer count
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
#[poise::command(slash_command, prefix_command, track_edits = true)]
|
||||
pub async fn stars(ctx: Context<'_>) -> Result<()> {
|
||||
trace!("Running stars command");
|
||||
|
||||
ctx.defer().await?;
|
||||
|
||||
let prismlauncher = ctx
|
||||
.data()
|
||||
.octocrab
|
||||
|
|
|
@ -13,19 +13,24 @@ include!(concat!(env!("OUT_DIR"), "/generated.rs"));
|
|||
static TAGS: Lazy<Vec<Tag>> = Lazy::new(|| serde_json::from_str(env!("TAGS")).unwrap());
|
||||
|
||||
/// Send a tag
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
track_edits = true,
|
||||
help_text_fn = help
|
||||
)]
|
||||
pub async fn tag(
|
||||
ctx: Context<'_>,
|
||||
#[description = "the copypasta you want to send"] name: Choice,
|
||||
user: Option<User>,
|
||||
#[description = "the tag to send"] name: Choice,
|
||||
#[description = "a user to mention"] user: Option<User>,
|
||||
) -> Result<()> {
|
||||
trace!("Running tag command");
|
||||
|
||||
let tag_file = name.as_str();
|
||||
let tag_id = name.as_str();
|
||||
let tag = TAGS
|
||||
.iter()
|
||||
.find(|t| t.file_name == tag_file)
|
||||
.ok_or_else(|| eyre!("Tried to get non-existent tag: {tag_file}"))?;
|
||||
.find(|t| t.id == tag_id)
|
||||
.ok_or_else(|| eyre!("Tried to get non-existent tag: {tag_id}"))?;
|
||||
|
||||
let frontmatter = &tag.frontmatter;
|
||||
|
||||
|
@ -49,6 +54,9 @@ pub async fn tag(
|
|||
}
|
||||
}
|
||||
|
||||
e = e.title(&frontmatter.title);
|
||||
e = e.description(&tag.content);
|
||||
|
||||
e
|
||||
};
|
||||
|
||||
|
@ -66,3 +74,13 @@ pub async fn tag(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn help() -> String {
|
||||
let tag_list = TAGS
|
||||
.iter()
|
||||
.map(|tag| format!("`{}`", tag.id))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
|
||||
format!("Available tags: {tag_list}")
|
||||
}
|
||||
|
|
|
@ -14,5 +14,6 @@ pub fn get() -> Vec<Command<Data, Report>> {
|
|||
general::say(),
|
||||
general::stars(),
|
||||
general::tag(),
|
||||
general::help(),
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue