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