refactor!: use poise 0.6.1
This commit is contained in:
parent
203ba111cc
commit
7252ced3cb
16 changed files with 700 additions and 512 deletions
|
@ -1,11 +1,16 @@
|
|||
use crate::{consts, Context};
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use poise::serenity_prelude::CreateEmbed;
|
||||
use poise::CreateReply;
|
||||
|
||||
/// Returns the number of members in the server
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn members(ctx: Context<'_>) -> Result<()> {
|
||||
let guild = ctx.guild().ok_or_else(|| eyre!("Couldn't fetch guild!"))?;
|
||||
let guild = ctx
|
||||
.guild()
|
||||
.ok_or_else(|| eyre!("Couldn't fetch guild!"))?
|
||||
.to_owned();
|
||||
|
||||
let count = guild.member_count;
|
||||
let online = if let Some(count) = guild.approximate_presence_count {
|
||||
|
@ -14,13 +19,12 @@ pub async fn members(ctx: Context<'_>) -> Result<()> {
|
|||
"Undefined".to_string()
|
||||
};
|
||||
|
||||
ctx.send(|m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!("{count} total members!"))
|
||||
.description(format!("{online} online members"))
|
||||
.color(consts::COLORS["blue"])
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
let embed = CreateEmbed::new()
|
||||
.title(format!("{count} total members!"))
|
||||
.description(format!("{online} online members"))
|
||||
.color(consts::COLORS["blue"]);
|
||||
let reply = CreateReply::default().embed(embed);
|
||||
|
||||
ctx.send(reply).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ use crate::api::rory::get_rory;
|
|||
use crate::Context;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use poise::serenity_prelude::{CreateEmbed, CreateEmbedFooter};
|
||||
use poise::CreateReply;
|
||||
|
||||
/// Gets a Rory photo!
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
|
@ -11,19 +13,22 @@ pub async fn rory(
|
|||
) -> Result<()> {
|
||||
let rory = get_rory(id).await?;
|
||||
|
||||
ctx.send(|m| {
|
||||
m.embed(|e| {
|
||||
if let Some(error) = rory.error {
|
||||
e.title("Error!").description(error)
|
||||
} else {
|
||||
e.title("Rory :3")
|
||||
.url(&rory.url)
|
||||
.image(rory.url)
|
||||
.footer(|f| f.text(format!("ID {}", rory.id)))
|
||||
}
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
let embed = {
|
||||
let embed = CreateEmbed::new();
|
||||
if let Some(error) = rory.error {
|
||||
embed.title("Error!").description(error)
|
||||
} else {
|
||||
let footer = CreateEmbedFooter::new(format!("ID {}", rory.id));
|
||||
embed
|
||||
.title("Rory :3")
|
||||
.url(&rory.url)
|
||||
.image(rory.url)
|
||||
.footer(footer)
|
||||
}
|
||||
};
|
||||
|
||||
let reply = CreateReply::default().embed(embed);
|
||||
ctx.send(reply).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::Context;
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use poise::serenity_prelude::{CreateEmbed, CreateEmbedAuthor, CreateMessage};
|
||||
|
||||
/// Say something through the bot
|
||||
#[poise::command(
|
||||
|
@ -11,7 +12,10 @@ use color_eyre::eyre::{eyre, Result};
|
|||
required_permissions = "MODERATE_MEMBERS"
|
||||
)]
|
||||
pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: String) -> Result<()> {
|
||||
let guild = ctx.guild().ok_or_else(|| eyre!("Couldn't get guild!"))?;
|
||||
let guild = ctx
|
||||
.guild()
|
||||
.ok_or_else(|| eyre!("Couldn't get guild!"))?
|
||||
.to_owned();
|
||||
let channel = ctx
|
||||
.guild_channel()
|
||||
.await
|
||||
|
@ -28,23 +32,16 @@ pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: Str
|
|||
.find(|c| c.0 == &channel_id)
|
||||
.ok_or_else(|| eyre!("Couldn't get log channel from guild!"))?;
|
||||
|
||||
log_channel
|
||||
.1
|
||||
.clone()
|
||||
.guild()
|
||||
.ok_or_else(|| eyre!("Couldn't cast channel we found from guild as GuildChannel?????"))?
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(|e| {
|
||||
e.title("Say command used!")
|
||||
.description(content)
|
||||
.author(|a| {
|
||||
a.name(ctx.author().tag()).icon_url(
|
||||
ctx.author().avatar_url().unwrap_or("undefined".to_string()),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
let author = CreateEmbedAuthor::new(ctx.author().tag())
|
||||
.icon_url(ctx.author().avatar_url().unwrap_or("Undefined".to_string()));
|
||||
|
||||
let embed = CreateEmbed::default()
|
||||
.title("Say command used!")
|
||||
.description(content)
|
||||
.author(author);
|
||||
|
||||
let message = CreateMessage::new().embed(embed);
|
||||
log_channel.1.send_message(ctx, message).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use crate::{consts::COLORS, Context};
|
||||
use crate::{consts, Context};
|
||||
|
||||
use color_eyre::eyre::{Context as _, Result};
|
||||
use poise::serenity_prelude::CreateEmbed;
|
||||
use poise::CreateReply;
|
||||
|
||||
/// Returns GitHub stargazer count
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
|
@ -19,13 +21,12 @@ pub async fn stars(ctx: Context<'_>) -> Result<()> {
|
|||
"undefined".to_string()
|
||||
};
|
||||
|
||||
ctx.send(|m| {
|
||||
m.embed(|e| {
|
||||
e.title(format!("⭐ {count} total stars!"))
|
||||
.color(COLORS["yellow"])
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
let embed = CreateEmbed::new()
|
||||
.title(format!("⭐ {count} total stars!"))
|
||||
.color(consts::COLORS["yellow"]);
|
||||
let reply = CreateReply::default().embed(embed);
|
||||
|
||||
ctx.send(reply).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ use std::env;
|
|||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use poise::serenity_prelude::{Color, User};
|
||||
use poise::serenity_prelude::{Color, CreateEmbed, User};
|
||||
use poise::CreateReply;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
|
||||
static TAGS: Lazy<Vec<Tag>> = Lazy::new(|| serde_json::from_str(env!("TAGS")).unwrap());
|
||||
|
@ -25,36 +26,40 @@ pub async fn tag(
|
|||
|
||||
let frontmatter = &tag.frontmatter;
|
||||
|
||||
ctx.send(|m| {
|
||||
if let Some(user) = user {
|
||||
m.content(format!("<@{}>", user.id));
|
||||
let embed = {
|
||||
let mut e = CreateEmbed::new();
|
||||
|
||||
if let Some(color) = &frontmatter.color {
|
||||
let color = *consts::COLORS
|
||||
.get(color.as_str())
|
||||
.unwrap_or(&Color::default());
|
||||
e = e.color(color);
|
||||
}
|
||||
|
||||
m.embed(|e| {
|
||||
e.title(&frontmatter.title);
|
||||
e.description(&tag.content);
|
||||
if let Some(image) = &frontmatter.image {
|
||||
e = e.image(image);
|
||||
}
|
||||
|
||||
if let Some(color) = &frontmatter.color {
|
||||
let color = *consts::COLORS
|
||||
.get(color.as_str())
|
||||
.unwrap_or(&Color::default());
|
||||
e.color(color);
|
||||
if let Some(fields) = &frontmatter.fields {
|
||||
for field in fields {
|
||||
e = e.field(&field.name, &field.value, field.inline);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(image) = &frontmatter.image {
|
||||
e.image(image);
|
||||
}
|
||||
e
|
||||
};
|
||||
|
||||
if let Some(fields) = &frontmatter.fields {
|
||||
for field in fields {
|
||||
e.field(&field.name, &field.value, field.inline);
|
||||
}
|
||||
}
|
||||
let reply = {
|
||||
let mut r = CreateReply::default();
|
||||
|
||||
e
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
if let Some(user) = user {
|
||||
r = r.content(format!("<@{}>", user.id));
|
||||
}
|
||||
|
||||
r.embed(embed)
|
||||
};
|
||||
|
||||
ctx.send(reply).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue