log more actions + tidy up things
This commit is contained in:
parent
651f14d724
commit
915ef54dc3
14 changed files with 56 additions and 19 deletions
|
@ -2,10 +2,12 @@ use crate::api::dadjoke;
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use log::trace;
|
||||||
|
|
||||||
/// It's a joke
|
/// It's a joke
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn joke(ctx: Context<'_>) -> Result<()> {
|
pub async fn joke(ctx: Context<'_>) -> Result<()> {
|
||||||
|
trace!("Running joke command");
|
||||||
let joke = dadjoke::get_joke().await?;
|
let joke = dadjoke::get_joke().await?;
|
||||||
|
|
||||||
ctx.reply(joke).await?;
|
ctx.reply(joke).await?;
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use crate::{consts, Context};
|
use crate::{consts, Context};
|
||||||
|
|
||||||
use eyre::{OptionExt, Result};
|
use eyre::{OptionExt, Result};
|
||||||
|
use log::trace;
|
||||||
use poise::serenity_prelude::CreateEmbed;
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Returns the number of members in the server
|
/// Returns the number of members in the server
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn members(ctx: Context<'_>) -> Result<()> {
|
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 guild = ctx.guild().ok_or_eyre("Couldn't fetch guild!")?.to_owned();
|
||||||
|
|
||||||
let count = guild.member_count;
|
let count = guild.member_count;
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use log::trace;
|
||||||
|
|
||||||
/// Replies with pong!
|
/// Replies with pong!
|
||||||
#[poise::command(slash_command, prefix_command, ephemeral)]
|
#[poise::command(slash_command, prefix_command, ephemeral)]
|
||||||
pub async fn ping(ctx: Context<'_>) -> Result<()> {
|
pub async fn ping(ctx: Context<'_>) -> Result<()> {
|
||||||
|
trace!("Running ping command!");
|
||||||
ctx.reply("Pong!").await?;
|
ctx.reply("Pong!").await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::api::rory;
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use log::trace;
|
||||||
use poise::serenity_prelude::{CreateEmbed, CreateEmbedFooter};
|
use poise::serenity_prelude::{CreateEmbed, CreateEmbedFooter};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ pub async fn rory(
|
||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "specify a Rory ID"] id: Option<u64>,
|
#[description = "specify a Rory ID"] id: Option<u64>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
trace!("Running rory command");
|
||||||
let rory = rory::get(id).await?;
|
let rory = rory::get(id).await?;
|
||||||
|
|
||||||
let embed = {
|
let embed = {
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: Str
|
||||||
channel.say(ctx, &content).await?;
|
channel.say(ctx, &content).await?;
|
||||||
ctx.say("I said what you said!").await?;
|
ctx.say("I said what you said!").await?;
|
||||||
|
|
||||||
if let Some(channel_id) = ctx.data().config.discord.channels.say_log_channel_id {
|
if let Some(channel_id) = ctx.data().config.discord.channels().say_log_channel_id() {
|
||||||
let log_channel = guild
|
let log_channel = guild
|
||||||
.channels
|
.channels
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
use crate::{consts, Context};
|
use crate::{consts, Context};
|
||||||
|
|
||||||
use eyre::{Context as _, Result};
|
use eyre::{Context as _, Result};
|
||||||
|
use log::trace;
|
||||||
use poise::serenity_prelude::CreateEmbed;
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
|
||||||
/// Returns GitHub stargazer count
|
/// Returns GitHub stargazer count
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn stars(ctx: Context<'_>) -> Result<()> {
|
pub async fn stars(ctx: Context<'_>) -> Result<()> {
|
||||||
|
trace!("Running stars command");
|
||||||
|
|
||||||
let prismlauncher = ctx
|
let prismlauncher = ctx
|
||||||
.data()
|
.data()
|
||||||
.octocrab
|
.octocrab
|
||||||
|
|
|
@ -3,7 +3,8 @@ use crate::tags::Tag;
|
||||||
use crate::{consts, Context};
|
use crate::{consts, Context};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use eyre::{OptionExt, Result};
|
use eyre::{eyre, Result};
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use poise::serenity_prelude::{Color, CreateEmbed, User};
|
use poise::serenity_prelude::{Color, CreateEmbed, User};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
@ -18,11 +19,13 @@ pub async fn tag(
|
||||||
#[description = "the copypasta you want to send"] name: Choice,
|
#[description = "the copypasta you want to send"] name: Choice,
|
||||||
user: Option<User>,
|
user: Option<User>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
trace!("Running tag command");
|
||||||
|
|
||||||
let tag_file = name.as_str();
|
let tag_file = name.as_str();
|
||||||
let tag = TAGS
|
let tag = TAGS
|
||||||
.iter()
|
.iter()
|
||||||
.find(|t| t.file_name == tag_file)
|
.find(|t| t.file_name == tag_file)
|
||||||
.ok_or_eyre("Tried to get non-existent tag: {tag_file}")?;
|
.ok_or_else(|| eyre!("Tried to get non-existent tag: {tag_file}"))?;
|
||||||
|
|
||||||
let frontmatter = &tag.frontmatter;
|
let frontmatter = &tag.frontmatter;
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,21 @@ use std::str::FromStr;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use poise::serenity_prelude::ChannelId;
|
use poise::serenity_prelude::ChannelId;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct RefractionChannels {
|
pub struct RefractionChannels {
|
||||||
pub say_log_channel_id: Option<ChannelId>,
|
say_log_channel_id: Option<ChannelId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub channels: RefractionChannels,
|
channels: RefractionChannels,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RefractionChannels {
|
impl RefractionChannels {
|
||||||
|
pub fn new(say_log_channel_id: Option<ChannelId>) -> Self {
|
||||||
|
Self { say_log_channel_id }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_from_env() -> Self {
|
pub fn new_from_env() -> Self {
|
||||||
let say_log_channel_id = Self::get_channel_from_env("DISCORD_SAY_LOG_CHANNELID");
|
let say_log_channel_id = Self::get_channel_from_env("DISCORD_SAY_LOG_CHANNELID");
|
||||||
|
|
||||||
|
@ -23,7 +27,7 @@ impl RefractionChannels {
|
||||||
warn!("DISCORD_SAY_LOG_CHANNELID is empty; this will disable logging in your server.");
|
warn!("DISCORD_SAY_LOG_CHANNELID is empty; this will disable logging in your server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { say_log_channel_id }
|
Self::new(say_log_channel_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_channel_from_env(var: &str) -> Option<ChannelId> {
|
fn get_channel_from_env(var: &str) -> Option<ChannelId> {
|
||||||
|
@ -31,12 +35,24 @@ impl RefractionChannels {
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|env_var| ChannelId::from_str(&env_var).ok())
|
.and_then(|env_var| ChannelId::from_str(&env_var).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn say_log_channel_id(self) -> Option<ChannelId> {
|
||||||
|
self.say_log_channel_id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
pub fn new(channels: RefractionChannels) -> Self {
|
||||||
|
Self { channels }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_from_env() -> Self {
|
pub fn new_from_env() -> Self {
|
||||||
let channels = RefractionChannels::new_from_env();
|
let channels = RefractionChannels::new_from_env();
|
||||||
|
|
||||||
Self { channels }
|
Self::new(channels)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channels(self) -> RefractionChannels {
|
||||||
|
self.channels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use eyre::{Context as _, Result};
|
use eyre::{Context as _, Result};
|
||||||
|
use log::trace;
|
||||||
use poise::serenity_prelude::{Context, InteractionType, Reaction};
|
use poise::serenity_prelude::{Context, InteractionType, Reaction};
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
|
pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
|
||||||
|
@ -17,6 +18,7 @@ pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
|
||||||
&& interaction.user == user
|
&& interaction.user == user
|
||||||
&& reaction.emoji.unicode_eq("❌")
|
&& reaction.emoji.unicode_eq("❌")
|
||||||
{
|
{
|
||||||
|
trace!("Deleting our own message at the request of {}", user.tag());
|
||||||
message.delete(ctx).await?;
|
message.delete(ctx).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
use log::trace;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use poise::serenity_prelude::{Context, Message};
|
use poise::serenity_prelude::{Context, Message};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
|
@ -6,7 +7,7 @@ use regex::Regex;
|
||||||
|
|
||||||
static ETA_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\beta\b").unwrap());
|
static ETA_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\beta\b").unwrap());
|
||||||
|
|
||||||
pub const ETA_MESSAGES: [&str; 16] = [
|
const ETA_MESSAGES: [&str; 16] = [
|
||||||
"Sometime",
|
"Sometime",
|
||||||
"Some day",
|
"Some day",
|
||||||
"Not far",
|
"Not far",
|
||||||
|
@ -27,6 +28,7 @@ pub const ETA_MESSAGES: [&str; 16] = [
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
|
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
|
||||||
if !ETA_REGEX.is_match(&message.content) {
|
if !ETA_REGEX.is_match(&message.content) {
|
||||||
|
trace!("The message '{}' (probably) doesn't say ETA", message.content);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,14 @@ use crate::{api, Data};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use log::{debug, trace};
|
use log::trace;
|
||||||
use poise::serenity_prelude::{Context, Message};
|
use poise::serenity_prelude::{Context, Message};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
const PK_DELAY_SEC: Duration = Duration::from_secs(1000);
|
const PK_DELAY_SEC: Duration = Duration::from_secs(1000);
|
||||||
|
|
||||||
pub async fn is_message_proxied(message: &Message) -> Result<bool> {
|
pub async fn is_message_proxied(message: &Message) -> Result<bool> {
|
||||||
debug!(
|
trace!(
|
||||||
"Waiting on PluralKit API for {} seconds",
|
"Waiting on PluralKit API for {} seconds",
|
||||||
PK_DELAY_SEC.as_secs()
|
PK_DELAY_SEC.as_secs()
|
||||||
);
|
);
|
||||||
|
@ -22,7 +22,7 @@ pub async fn is_message_proxied(message: &Message) -> Result<bool> {
|
||||||
|
|
||||||
pub async fn handle(_: &Context, msg: &Message, data: &Data) -> Result<()> {
|
pub async fn handle(_: &Context, msg: &Message, data: &Data) -> Result<()> {
|
||||||
if msg.webhook_id.is_some() {
|
if msg.webhook_id.is_some() {
|
||||||
debug!(
|
trace!(
|
||||||
"Message {} has a webhook ID. Checking if it was sent through PluralKit",
|
"Message {} has a webhook ID. Checking if it was sent through PluralKit",
|
||||||
msg.id
|
msg.id
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use eyre::{eyre, OptionExt, Result};
|
use eyre::{eyre, OptionExt, Result};
|
||||||
use log::debug;
|
use log::{debug, trace};
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel,
|
ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> {
|
pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> {
|
||||||
if thread.kind != ChannelType::PublicThread {
|
if thread.kind != ChannelType::PublicThread {
|
||||||
debug!("Not doing support onboard in non-thread channel");
|
trace!("Not doing support onboard in non-public thread channel");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> {
|
||||||
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?
|
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?
|
||||||
.name(ctx)
|
.name(ctx)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(String::new())
|
.unwrap_or_default()
|
||||||
!= "support"
|
!= "support"
|
||||||
{
|
{
|
||||||
debug!("Not posting onboarding message to threads outside of support");
|
debug!("Not posting onboarding message to threads outside of support");
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use eyre::{eyre, Context as _, Report, Result};
|
use eyre::{eyre, Context as _, Report, Result};
|
||||||
use log::{info, warn};
|
use log::{info, trace, warn};
|
||||||
|
|
||||||
use octocrab::Octocrab;
|
use octocrab::Octocrab;
|
||||||
use poise::{
|
use poise::{
|
||||||
|
@ -71,6 +71,7 @@ async fn setup(
|
||||||
"Couldn't connect to storage! Is your daemon running?"
|
"Couldn't connect to storage! Is your daemon running?"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
trace!("Redis connection looks good!");
|
||||||
|
|
||||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
info!("Registered global commands!");
|
info!("Registered global commands!");
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use eyre::{eyre, Context as _, Result};
|
use eyre::{eyre, Context as _, Result};
|
||||||
use log::debug;
|
use log::{debug, trace};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
ChannelId, ChannelType, Colour, Context, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter,
|
ChannelId, ChannelType, Colour, Context, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter,
|
||||||
|
@ -32,7 +32,9 @@ pub async fn resolve(ctx: &Context, msg: &Message) -> Result<Vec<CreateEmbed>> {
|
||||||
|
|
||||||
let mut embeds: Vec<CreateEmbed> = vec![];
|
let mut embeds: Vec<CreateEmbed> = vec![];
|
||||||
|
|
||||||
for (_, [_server_id, channel_id, message_id]) in matches {
|
for (url, [_server_id, channel_id, message_id]) in matches {
|
||||||
|
trace!("Attempting to resolve message {message_id} from URL {url}");
|
||||||
|
|
||||||
let channel = ChannelId::from_str(channel_id)
|
let channel = ChannelId::from_str(channel_id)
|
||||||
.wrap_err_with(|| format!("Couldn't parse channel ID {channel_id}!"))?
|
.wrap_err_with(|| format!("Couldn't parse channel ID {channel_id}!"))?
|
||||||
.to_channel_cached(ctx.as_ref())
|
.to_channel_cached(ctx.as_ref())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue