...
This commit is contained in:
@ -4,6 +4,7 @@ use levenshtein::levenshtein;
|
||||
use regex_command_attr::command;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
http::AttachmentType,
|
||||
model::{
|
||||
interactions::InteractionResponseType, misc::Mentionable,
|
||||
prelude::InteractionApplicationCommandCallbackDataFlags,
|
||||
@ -12,6 +13,7 @@ use serenity::{
|
||||
|
||||
use crate::{
|
||||
component_models::{ComponentDataModel, Restrict},
|
||||
consts,
|
||||
consts::THEME_COLOR,
|
||||
framework::{CommandInvoke, CommandOptions, CreateGenericResponse, OptionValue},
|
||||
hooks::{CHECK_GUILD_PERMISSIONS_HOOK, CHECK_MANAGED_PERMISSIONS_HOOK},
|
||||
@ -424,4 +426,41 @@ Any commands ran as part of recording will be inconsequential")
|
||||
#[subcommand("avatar")]
|
||||
#[description("Change the webhook avatar")]
|
||||
#[arg(name = "url", description = "The URL of the image to use", kind = "String", required = true)]
|
||||
async fn configure_webhook(ctx: &Context, invoke: CommandInvoke, args: CommandOptions) {}
|
||||
async fn configure_webhook(ctx: &Context, invoke: CommandInvoke, args: CommandOptions) {
|
||||
let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
|
||||
let mut channel_data = ctx.channel_data(invoke.channel_id()).await.unwrap();
|
||||
|
||||
let (username, avatar) = (
|
||||
args.get("username").map_or("Reminder".to_string(), |i| i.to_string()),
|
||||
args.get("url").map_or(consts::DEFAULT_AVATAR, |i| AttachmentType::Image(&i.to_string())),
|
||||
);
|
||||
|
||||
if let (Some(id), Some(token)) = (channel_data.webhook_id, channel_data.webhook_token) {
|
||||
match ctx.http.get_webhook_with_token(id, &token).await {
|
||||
Ok(mut webhook) => {
|
||||
webhook.edit(&ctx, Some(username), Some(avatar)).await;
|
||||
}
|
||||
|
||||
Err(_) => {
|
||||
let webhook = invoke
|
||||
.channel_id()
|
||||
.create_webhook_with_avatar(&ctx, username, avatar)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
channel_data.webhook_token = webhook.token;
|
||||
channel_data.webhook_id = Some(webhook.id.0);
|
||||
|
||||
channel_data.commit_changes(&pool).await;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let webhook =
|
||||
invoke.channel_id().create_webhook_with_avatar(&ctx, username, avatar).await.unwrap();
|
||||
|
||||
channel_data.webhook_token = webhook.token;
|
||||
channel_data.webhook_id = Some(webhook.id.0);
|
||||
|
||||
channel_data.commit_changes(&pool).await;
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,20 @@ pub const CHARACTERS: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX
|
||||
|
||||
const THEME_COLOR_FALLBACK: u32 = 0x8fb677;
|
||||
|
||||
pub const DEFAULT_AVATAR: AttachmentType = (
|
||||
include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/",
|
||||
env!("WEBHOOK_AVATAR", "WEBHOOK_AVATAR not provided for compilation")
|
||||
)) as &[u8],
|
||||
env!("WEBHOOK_AVATAR"),
|
||||
)
|
||||
.into();
|
||||
|
||||
use std::{collections::HashSet, env, iter::FromIterator};
|
||||
|
||||
use regex::{Regex, RegexBuilder};
|
||||
use serenity::http::AttachmentType;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref REGEX_CHANNEL: Regex = Regex::new(r#"^\s*<#(\d+)>\s*$"#).unwrap();
|
||||
|
@ -15,6 +15,7 @@ use serenity::{
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use crate::{
|
||||
consts,
|
||||
consts::{MAX_TIME, MIN_INTERVAL},
|
||||
models::{
|
||||
channel_data::ChannelData,
|
||||
@ -29,20 +30,7 @@ async fn create_webhook(
|
||||
channel: GuildChannel,
|
||||
name: impl Display,
|
||||
) -> SerenityResult<Webhook> {
|
||||
channel
|
||||
.create_webhook_with_avatar(
|
||||
ctx.http(),
|
||||
name,
|
||||
(
|
||||
include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/",
|
||||
env!("WEBHOOK_AVATAR", "WEBHOOK_AVATAR not provided for compilation")
|
||||
)) as &[u8],
|
||||
env!("WEBHOOK_AVATAR"),
|
||||
),
|
||||
)
|
||||
.await
|
||||
channel.create_webhook_with_avatar(ctx.http(), name, consts::DEFAULT_AVATAR).await
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
|
Reference in New Issue
Block a user