mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 01:00:49 +00:00
Formatting
This commit is contained in:
parent
6944ddfe75
commit
45425a4bc4
2 changed files with 57 additions and 35 deletions
|
@ -20,8 +20,8 @@ mod roles;
|
||||||
mod votes;
|
mod votes;
|
||||||
|
|
||||||
use roles::{
|
use roles::{
|
||||||
ADD_COMMAND, LIST_COMMAND, REMOVE_COMMAND, RMROLEMESSAGE_COMMAND, ROLEMESSAGE_COMMAND, UPDATEROLEMESSAGE_COMMAND,
|
ADD_COMMAND, LIST_COMMAND, REMOVE_COMMAND, RMROLEMESSAGE_COMMAND, ROLEMESSAGE_COMMAND,
|
||||||
TOGGLE_COMMAND,
|
TOGGLE_COMMAND, UPDATEROLEMESSAGE_COMMAND,
|
||||||
};
|
};
|
||||||
use votes::VOTE_COMMAND;
|
use votes::VOTE_COMMAND;
|
||||||
|
|
||||||
|
@ -30,7 +30,17 @@ pub use roles::ReactionWatchers;
|
||||||
#[group]
|
#[group]
|
||||||
#[description = "Community related commands. Usually comes with some sort of delays, since it involves pinging"]
|
#[description = "Community related commands. Usually comes with some sort of delays, since it involves pinging"]
|
||||||
#[only_in("guilds")]
|
#[only_in("guilds")]
|
||||||
#[commands(choose, vote, add, list, remove, toggle, rolemessage, rmrolemessage, updaterolemessage)]
|
#[commands(
|
||||||
|
choose,
|
||||||
|
vote,
|
||||||
|
add,
|
||||||
|
list,
|
||||||
|
remove,
|
||||||
|
toggle,
|
||||||
|
rolemessage,
|
||||||
|
rmrolemessage,
|
||||||
|
updaterolemessage
|
||||||
|
)]
|
||||||
struct Community;
|
struct Community;
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
use crate::db::Roles as DB;
|
use crate::db::Roles as DB;
|
||||||
use serenity::{framework::standard::{macros::command, Args, CommandResult}, model::{channel::{Message, ReactionType}, guild::Role, id::RoleId}, utils::MessageBuilder};
|
use serenity::{
|
||||||
|
framework::standard::{macros::command, Args, CommandResult},
|
||||||
|
model::{
|
||||||
|
channel::{Message, ReactionType},
|
||||||
|
guild::Role,
|
||||||
|
id::RoleId,
|
||||||
|
},
|
||||||
|
utils::MessageBuilder,
|
||||||
|
};
|
||||||
use youmubot_prelude::*;
|
use youmubot_prelude::*;
|
||||||
|
|
||||||
pub use reaction_watcher::Watchers as ReactionWatchers;
|
pub use reaction_watcher::Watchers as ReactionWatchers;
|
||||||
|
@ -262,7 +270,7 @@ fn role_from_string(role: &str, roles: &std::collections::HashMap<RoleId, Role>)
|
||||||
async fn rolemessage(ctx: &Context, m: &Message, args: Args) -> CommandResult {
|
async fn rolemessage(ctx: &Context, m: &Message, args: Args) -> CommandResult {
|
||||||
let (title, roles) = match parse(ctx, m, args).await? {
|
let (title, roles) = match parse(ctx, m, args).await? {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return Ok(())
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
let guild_id = m.guild_id.unwrap();
|
let guild_id = m.guild_id.unwrap();
|
||||||
|
@ -273,7 +281,11 @@ async fn rolemessage(ctx: &Context, m: &Message, args: Args) -> CommandResult {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn parse(ctx: &Context, m: &Message, mut args: Args) -> Result<Option<(String, Vec<(crate::db::Role, Role, ReactionType)>)>> {
|
async fn parse(
|
||||||
|
ctx: &Context,
|
||||||
|
m: &Message,
|
||||||
|
mut args: Args,
|
||||||
|
) -> Result<Option<(String, Vec<(crate::db::Role, Role, ReactionType)>)>> {
|
||||||
let title = args.single_quoted::<String>().unwrap();
|
let title = args.single_quoted::<String>().unwrap();
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
let guild_id = m.guild_id.unwrap();
|
let guild_id = m.guild_id.unwrap();
|
||||||
|
@ -335,7 +347,7 @@ async fn parse(ctx: &Context, m: &Message, mut args: Args) -> Result<Option<(Str
|
||||||
async fn updaterolemessage(ctx: &Context, m: &Message, args: Args) -> CommandResult {
|
async fn updaterolemessage(ctx: &Context, m: &Message, args: Args) -> CommandResult {
|
||||||
let (title, roles) = match parse(ctx, m, args).await? {
|
let (title, roles) = match parse(ctx, m, args).await? {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return Ok(())
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
let guild_id = m.guild_id.unwrap();
|
let guild_id = m.guild_id.unwrap();
|
||||||
|
@ -346,7 +358,8 @@ async fn updaterolemessage(ctx: &Context, m: &Message, args: Args) -> CommandRes
|
||||||
m.reply(&ctx, "No replied message found.").await?;
|
m.reply(&ctx, "No replied message found.").await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}.clone();
|
}
|
||||||
|
.clone();
|
||||||
|
|
||||||
if data
|
if data
|
||||||
.get::<ReactionWatchers>()
|
.get::<ReactionWatchers>()
|
||||||
|
@ -354,10 +367,10 @@ async fn updaterolemessage(ctx: &Context, m: &Message, args: Args) -> CommandRes
|
||||||
.remove(ctx, guild_id, message.id)
|
.remove(ctx, guild_id, message.id)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
data
|
data.get::<ReactionWatchers>()
|
||||||
.get::<ReactionWatchers>()
|
.unwrap()
|
||||||
.unwrap()
|
.setup(&mut *message, ctx.clone(), guild_id, title, roles)
|
||||||
.setup(&mut *message, ctx.clone(), guild_id, title, roles).await?;
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
m.reply(&ctx, "Message does not come with a reaction handler")
|
m.reply(&ctx, "Message does not come with a reaction handler")
|
||||||
.await
|
.await
|
||||||
|
@ -396,8 +409,6 @@ async fn rmrolemessage(ctx: &Context, m: &Message, _args: Args) -> CommandResult
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,9 +466,10 @@ mod reaction_watcher {
|
||||||
channel: ChannelId,
|
channel: ChannelId,
|
||||||
title: String,
|
title: String,
|
||||||
roles: Vec<(Role, DiscordRole, ReactionType)>,
|
roles: Vec<(Role, DiscordRole, ReactionType)>,
|
||||||
|
) -> Result<()> {
|
||||||
) -> Result<()> {
|
let mut msg = channel
|
||||||
let mut msg = channel.send_message(&ctx, |c| c.content("Youmu is setting up the message...")).await?;
|
.send_message(&ctx, |c| c.content("Youmu is setting up the message..."))
|
||||||
|
.await?;
|
||||||
self.setup(&mut msg, ctx, guild, title, roles).await
|
self.setup(&mut msg, ctx, guild, title, roles).await
|
||||||
}
|
}
|
||||||
pub async fn setup(
|
pub async fn setup(
|
||||||
|
@ -470,30 +482,30 @@ mod reaction_watcher {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Send a message
|
// Send a message
|
||||||
msg.edit(&ctx, |m| {
|
msg.edit(&ctx, |m| {
|
||||||
m.content({
|
m.content({
|
||||||
let mut builder = serenity::utils::MessageBuilder::new();
|
let mut builder = serenity::utils::MessageBuilder::new();
|
||||||
|
builder
|
||||||
|
.push_bold("Role Menu:")
|
||||||
|
.push(" ")
|
||||||
|
.push_bold_line_safe(&title)
|
||||||
|
.push_line("React to give yourself a role.")
|
||||||
|
.push_line("");
|
||||||
|
for (role, discord_role, emoji) in &roles {
|
||||||
builder
|
builder
|
||||||
.push_bold("Role Menu:")
|
.push(emoji)
|
||||||
.push(" ")
|
.push(" ")
|
||||||
.push_bold_line_safe(&title)
|
.push_bold_safe(&discord_role.name)
|
||||||
.push_line("React to give yourself a role.")
|
.push(": ")
|
||||||
|
.push_line_safe(&role.description)
|
||||||
.push_line("");
|
.push_line("");
|
||||||
for (role, discord_role, emoji) in &roles {
|
}
|
||||||
builder
|
builder
|
||||||
.push(emoji)
|
|
||||||
.push(" ")
|
|
||||||
.push_bold_safe(&discord_role.name)
|
|
||||||
.push(": ")
|
|
||||||
.push_line_safe(&role.description)
|
|
||||||
.push_line("");
|
|
||||||
}
|
|
||||||
builder
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.await?;
|
})
|
||||||
|
.await?;
|
||||||
// Do reactions
|
// Do reactions
|
||||||
for (_, _, emoji) in &roles {
|
for (_, _, emoji) in &roles {
|
||||||
msg.react(&ctx, emoji.clone()).await.ok();
|
msg.react(&ctx, emoji.clone()).await.ok();
|
||||||
}
|
}
|
||||||
// Store the message into the list.
|
// Store the message into the list.
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue