Don't message new members, don't talk to bots!

This commit is contained in:
Malte Tammena 2021-12-07 16:12:24 +01:00
parent 5f81690d16
commit 960a4447ce
5 changed files with 12 additions and 26 deletions

View file

@ -63,9 +63,6 @@ pub struct Args {
#[structopt(long, value_name = "ID", env = "GUILD_ADMIN_CHANNEL")]
pub admin_channel: u64,
#[structopt(long, value_name = "ID", env = "GUILD_INFO_CHANNEL")]
pub info_channel: u64,
#[structopt(long, value_name = "URL", env = "INFLUX_HOST")]
pub influx_host: Url,
@ -101,8 +98,4 @@ impl Args {
pub fn admin_channel(&self) -> ChannelId {
self.admin_channel.into()
}
pub fn info_channel(&self) -> ChannelId {
self.info_channel.into()
}
}

View file

@ -3,7 +3,7 @@
//! - `~ping`
//! - Pong!
//!
//! - `~invite Random#1234`
//! - `~invite Random#1234` (not possible)
//! - Invite someone into the guild
//!
//! - Member_add

View file

@ -39,6 +39,9 @@ impl EventHandler for Handler {
if guild_id != ARGS.guild_id {
return;
}
if new_member.user.bot {
return;
}
workflow_member_add(&ctx, new_member).await;
}
@ -52,6 +55,9 @@ impl EventHandler for Handler {
if guild_id != ARGS.guild_id {
return;
}
if user.bot {
return;
}
workflow_member_removal(&ctx, user).await;
}
}

View file

@ -19,7 +19,7 @@ pub async fn initial_state_sanitization(ctx: &Context) -> Result {
}
pub async fn workflow_member_add(ctx: &Context, new_member: Member) {
tracing::info!("Adding new member {:?}", new_member.user.name);
tracing::info!("Found new member {:?}", new_member.user.name);
// Keep track of the new member
State::write(ctx, |state| {
state.guild_members.insert(new_member.user.id.into())
@ -27,16 +27,13 @@ pub async fn workflow_member_add(ctx: &Context, new_member: Member) {
.await
.log_warn("adding new member to guild list");
// Notify about new arrival
admin_channel_say(ctx, format!("{} joined the guild!", new_member.user))
admin_channel_say(ctx, format!("New member {}!", new_member.user))
.await
.log_warn("notifying about new guild member");
// Greet the new member with a DM
welcome_new_member(ctx, &new_member)
.await
.log_warn("welcoming new member");
}
pub async fn workflow_member_removal(ctx: &Context, user: User) {
tracing::info!("Removing member {:?}", user.name);
let old_member: Option<GuildMember> =
State::write(ctx, |state| state.guild_members.take(&user.id))
.await
@ -49,17 +46,6 @@ pub async fn workflow_member_removal(ctx: &Context, user: User) {
}
}
async fn welcome_new_member(ctx: &Context, member: &Member) -> Result {
let channel = member.user.create_dm_channel(ctx.http.clone()).await?;
channel.send_message(ctx.http.clone(), |m| {
m.content(format!(r#"Hey {},
Welcome to the CCQCraft Server! Most information can be found in the {info_channel} channel! If you have any questions message either megamanmalte or Gim. Not me, I'm just a bot :)"#,
member.user.name,
info_channel=ARGS.info_channel()))
}).await?;
Ok(())
}
async fn admin_channel_say(ctx: &Context, what: impl fmt::Display) -> Result {
ARGS.admin_channel().say(ctx.http.clone(), what).await?;
Ok(())
@ -71,6 +57,8 @@ async fn catch_up_on_guild_members(ctx: &Context) -> Result {
.members(ctx.http.clone(), None, None)
.await?
.into_iter()
// I don't care about other bots!
.filter(|member| !member.user.bot)
.map(|member| member.user.id)
.collect();
let known_members: HashSet<_> = State::read(ctx, |state| {

View file

@ -39,7 +39,6 @@ impl RconCommand for WhoIsCmd<'_> {
// §6 ====== WhoIs:§c gloom_17 §6======\n§6 - Nick:§r gloom_17\n§6 - UUID:§r 1fea9fa1-7ee0-4c5f-b4d8-97185709cf33\n§6 - Health:§r 18.56/20\n§6 - Hunger:§r 16/20 (+0 saturation)\n§6 - Exp:§r 1,545 (Level 31)\n§6 - Location:§r (world, 443, 64, 73)\n§6 - Playtime:§r 2 days 2 hours 32 minutes\n§6 - Money:§r $0\n§6 - IP Address:§r /213.142.97.187\n§6 - Gamemode:§r survival\n§6 - God mode:§r §4false§r\n§6 - OP:§r §4false§r\n§6 - Fly mode:§r §4false§r (not flying)\n§6 - Speed:§r 0.2\n§6 - AFK:§r §4false§r\n§6 - Jail:§r §4false§r\n§6 - Muted:§r §4false§r\n
pub fn parse_whois_result(inp: &str) -> IResult<&str, WhoIs> {
dbg!(inp);
let list = tuple((
prop("Nick", parse_string),
prop("UUID", parse_string),