Working on the bot
This commit is contained in:
parent
7293e1d37d
commit
f0a95356d4
|
@ -1,20 +1,21 @@
|
|||
use crate::commands::Result;
|
||||
use serenity::{model::channel::Message, prelude::Context};
|
||||
use serenity::{framework::standard::CommandResult, model::channel::Message, prelude::Context};
|
||||
|
||||
/// Send a reply to the channel the message was received on.
|
||||
pub(crate) async fn send_reply<'m, S: std::string::ToString>(
|
||||
ctx: &Context,
|
||||
msg: &Message,
|
||||
message: S,
|
||||
) -> Result<serenity::model::channel::Message> {
|
||||
Ok(msg.channel_id.say(ctx, message.to_string()).await?)
|
||||
) -> CommandResult {
|
||||
msg.channel_id.say(ctx, message.to_string()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn send_splitted_by_lines_in_card<S: std::string::ToString>(
|
||||
ctx: &Context,
|
||||
msg: &Message,
|
||||
message: S,
|
||||
) -> Result<()> {
|
||||
) -> CommandResult {
|
||||
let mut buffer = String::from("\x60\x60\x60\n");
|
||||
for line in message.to_string().lines() {
|
||||
if buffer.len() + 4 + line.len() >= 2000 {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::debugln;
|
||||
use serenity::{
|
||||
framework::standard::{
|
||||
macros::{command, group},
|
||||
|
@ -7,6 +6,7 @@ use serenity::{
|
|||
model::prelude::*,
|
||||
prelude::*,
|
||||
};
|
||||
use log::debug;
|
||||
|
||||
#[group]
|
||||
#[commands(ban, kick)]
|
||||
|
@ -21,7 +21,7 @@ async fn kick(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
if let Ok(sender_member) = msg.member(ctx).await {
|
||||
for user in &msg.mentions {
|
||||
if let Some(member) = ctx.cache.member(msg.guild_id.unwrap(), user.id).await {
|
||||
debugln!("Kicking {:?}", user);
|
||||
debug!("Kicking {:?}", user);
|
||||
let kick = if let Some(role_member) = sender_member.highest_role_info(ctx).await {
|
||||
if let Some(role) = member.highest_role_info(ctx).await {
|
||||
role_member.1 > role.1
|
||||
|
@ -63,7 +63,7 @@ async fn ban(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
if let Ok(sender_member) = msg.member(ctx).await {
|
||||
for user in &msg.mentions {
|
||||
if let Some(member) = ctx.cache.member(msg.guild_id.unwrap(), user.id).await {
|
||||
debugln!("Kicking {:?}", user);
|
||||
debug!("Kicking {:?}", user);
|
||||
let kick = if let Some(role_member) = sender_member.highest_role_info(ctx).await {
|
||||
if let Some(role) = member.highest_role_info(ctx).await {
|
||||
role_member.1 > role.1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{api, data::ShardManagerContainer, debugln};
|
||||
use crate::{api, data::ShardManagerContainer};
|
||||
use futures::StreamExt;
|
||||
use log::error;
|
||||
use serenity::{
|
||||
|
@ -63,15 +63,7 @@ async fn latency(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
#[command]
|
||||
#[description = "Split a huge code"]
|
||||
#[bucket = "longcode"]
|
||||
pub async fn longcode(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
if let Err(e) = _longcode(ctx, msg, args).await {
|
||||
error!("Error in longcode : {:?}", e);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn _longcode(ctx: &Context, msg: &Message, mut args: Args) -> crate::commands::Result<()> {
|
||||
debugln!("_longcode : {:?}", args);
|
||||
pub async fn longcode(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
if let Ok(language) = args.single::<String>() {
|
||||
if !msg.attachments.is_empty() {
|
||||
let att = msg.attachments[0].clone();
|
||||
|
@ -177,14 +169,7 @@ async fn invite(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
|
||||
#[command]
|
||||
#[description = "Find who is the older"]
|
||||
pub async fn older(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
if let Err(e) = _older(ctx, msg, args).await {
|
||||
error!("Error in older : {:?}", e);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn _older(ctx: &Context, msg: &Message, mut args: Args) -> crate::commands::Result<()> {
|
||||
pub async fn older(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let mut number = 10;
|
||||
if !args.is_empty() {
|
||||
number = args.single::<usize>()?;
|
||||
|
|
|
@ -291,6 +291,7 @@ async fn is_mute(
|
|||
member: &PartialMember,
|
||||
guild_id: GuildId,
|
||||
) -> tokio::io::Result<bool> {
|
||||
|
||||
let mut data = ctx.data.write().await;
|
||||
let data = data
|
||||
.get_mut::<GuildOptionsKey>()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use crate::{
|
||||
api, commands,
|
||||
data::{BulletsContainer, GuildOptions, GuildOptionsKey},
|
||||
debugln,
|
||||
};
|
||||
use log::error;
|
||||
use log::{debug, error, trace};
|
||||
use rand::Rng;
|
||||
use serenity::{
|
||||
framework::standard::{
|
||||
|
@ -26,8 +25,10 @@ struct Roulette;
|
|||
async fn shot(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let _message = args.message().trim_end();
|
||||
if _message == "shot" || _message == "" {
|
||||
if let Err(e) = _shot(ctx, msg).await {
|
||||
error!("Error in shot : {:?}", e);
|
||||
if rand::thread_rng().gen_range(0, 6) == 0 {
|
||||
api::send_reply(ctx, &msg, "💥").await?;
|
||||
} else {
|
||||
api::send_reply(&ctx, &msg, format!("Click ! Reloading")).await?;
|
||||
}
|
||||
} else if let Err(e) = api::send_reply(
|
||||
ctx,
|
||||
|
@ -41,30 +42,6 @@ async fn shot(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn _shot(ctx: &Context, msg: &Message) -> commands::Result<()> {
|
||||
let mut data = ctx.data.write().await;
|
||||
let bullets_map = data
|
||||
.get_mut::<BulletsContainer>()
|
||||
.expect("Expected CommandCounter in TypeMap.");
|
||||
let bullets = bullets_map
|
||||
.entry(msg.author.id.0)
|
||||
.or_insert((5, rand::thread_rng().gen_range(0, 6)));
|
||||
if bullets.0 == bullets.1 {
|
||||
api::send_reply(ctx, &msg, "💥").await?;
|
||||
*bullets = (5, rand::thread_rng().gen_range(0, 6));
|
||||
} else {
|
||||
*bullets = (bullets.0 - 1, bullets.1);
|
||||
api::send_reply(
|
||||
&ctx,
|
||||
&msg,
|
||||
format!("Click ! bullets remaining : {}", bullets.0 + 1),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
log::trace!("Bullets Map : {:?}", bullets_map);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[description = "Reload"]
|
||||
#[bucket = "roulette"]
|
||||
|
@ -97,7 +74,7 @@ async fn check(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
.entry(msg.author.id.0)
|
||||
.or_insert((5, rand::thread_rng().gen_range(0, 6)));
|
||||
msg.channel_id.say(ctx, format!("Because you are a little shit, you open your barrel and you see that the bullet was at the {} position", bullet_to_str(bullets.1 + 1))).await?;
|
||||
debugln!("Bullets Map : {:?}", bullets_map);
|
||||
debug!("Bullets Map : {:?}", bullets_map);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -129,7 +106,7 @@ async fn kick(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn _kick(ctx: &Context, msg: &Message) -> commands::Result<()> {
|
||||
async fn _kick(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
if let Some(guild_id) = &msg.guild_id {
|
||||
let mut data = ctx.data.write().await;
|
||||
let guilds_options = data
|
||||
|
@ -169,7 +146,7 @@ async fn _kick(ctx: &Context, msg: &Message) -> commands::Result<()> {
|
|||
)
|
||||
.await?;
|
||||
}
|
||||
debugln!("Bullets Map : {:?}", bullets_map);
|
||||
debug!("Bullets Map : {:?}", bullets_map);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -203,6 +180,6 @@ async fn disable_kick(ctx: &Context, msg: &Message, mut args: Args) -> CommandRe
|
|||
|
||||
entry.save_async(guild_id.0).await?;
|
||||
}
|
||||
log::debug!("{:?}", guilds_options);
|
||||
debug!("{:?}", guilds_options);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue