Don't message new members, don't talk to bots!
This commit is contained in:
parent
5f81690d16
commit
960a4447ce
|
@ -63,9 +63,6 @@ pub struct Args {
|
||||||
#[structopt(long, value_name = "ID", env = "GUILD_ADMIN_CHANNEL")]
|
#[structopt(long, value_name = "ID", env = "GUILD_ADMIN_CHANNEL")]
|
||||||
pub admin_channel: u64,
|
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")]
|
#[structopt(long, value_name = "URL", env = "INFLUX_HOST")]
|
||||||
pub influx_host: Url,
|
pub influx_host: Url,
|
||||||
|
|
||||||
|
@ -101,8 +98,4 @@ impl Args {
|
||||||
pub fn admin_channel(&self) -> ChannelId {
|
pub fn admin_channel(&self) -> ChannelId {
|
||||||
self.admin_channel.into()
|
self.admin_channel.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn info_channel(&self) -> ChannelId {
|
|
||||||
self.info_channel.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//! - `~ping`
|
//! - `~ping`
|
||||||
//! - Pong!
|
//! - Pong!
|
||||||
//!
|
//!
|
||||||
//! - `~invite Random#1234`
|
//! - `~invite Random#1234` (not possible)
|
||||||
//! - Invite someone into the guild
|
//! - Invite someone into the guild
|
||||||
//!
|
//!
|
||||||
//! - Member_add
|
//! - Member_add
|
||||||
|
|
|
@ -39,6 +39,9 @@ impl EventHandler for Handler {
|
||||||
if guild_id != ARGS.guild_id {
|
if guild_id != ARGS.guild_id {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if new_member.user.bot {
|
||||||
|
return;
|
||||||
|
}
|
||||||
workflow_member_add(&ctx, new_member).await;
|
workflow_member_add(&ctx, new_member).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +55,9 @@ impl EventHandler for Handler {
|
||||||
if guild_id != ARGS.guild_id {
|
if guild_id != ARGS.guild_id {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if user.bot {
|
||||||
|
return;
|
||||||
|
}
|
||||||
workflow_member_removal(&ctx, user).await;
|
workflow_member_removal(&ctx, user).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub async fn initial_state_sanitization(ctx: &Context) -> Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn workflow_member_add(ctx: &Context, new_member: Member) {
|
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
|
// Keep track of the new member
|
||||||
State::write(ctx, |state| {
|
State::write(ctx, |state| {
|
||||||
state.guild_members.insert(new_member.user.id.into())
|
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
|
.await
|
||||||
.log_warn("adding new member to guild list");
|
.log_warn("adding new member to guild list");
|
||||||
// Notify about new arrival
|
// 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
|
.await
|
||||||
.log_warn("notifying about new guild member");
|
.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) {
|
pub async fn workflow_member_removal(ctx: &Context, user: User) {
|
||||||
|
tracing::info!("Removing member {:?}", user.name);
|
||||||
let old_member: Option<GuildMember> =
|
let old_member: Option<GuildMember> =
|
||||||
State::write(ctx, |state| state.guild_members.take(&user.id))
|
State::write(ctx, |state| state.guild_members.take(&user.id))
|
||||||
.await
|
.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 {
|
async fn admin_channel_say(ctx: &Context, what: impl fmt::Display) -> Result {
|
||||||
ARGS.admin_channel().say(ctx.http.clone(), what).await?;
|
ARGS.admin_channel().say(ctx.http.clone(), what).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -71,6 +57,8 @@ async fn catch_up_on_guild_members(ctx: &Context) -> Result {
|
||||||
.members(ctx.http.clone(), None, None)
|
.members(ctx.http.clone(), None, None)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
// I don't care about other bots!
|
||||||
|
.filter(|member| !member.user.bot)
|
||||||
.map(|member| member.user.id)
|
.map(|member| member.user.id)
|
||||||
.collect();
|
.collect();
|
||||||
let known_members: HashSet<_> = State::read(ctx, |state| {
|
let known_members: HashSet<_> = State::read(ctx, |state| {
|
||||||
|
|
|
@ -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
|
// §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> {
|
pub fn parse_whois_result(inp: &str) -> IResult<&str, WhoIs> {
|
||||||
dbg!(inp);
|
|
||||||
let list = tuple((
|
let list = tuple((
|
||||||
prop("Nick", parse_string),
|
prop("Nick", parse_string),
|
||||||
prop("UUID", parse_string),
|
prop("UUID", parse_string),
|
||||||
|
|
Loading…
Reference in a new issue