Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
chore: antiraid bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
junepark678 committed Jul 23, 2023
1 parent c02590e commit 6ee9b06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 59 deletions.
43 changes: 10 additions & 33 deletions bridget/cogs/antiraid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import discord
import os
import json

from asyncio import Lock
from datetime import datetime, timedelta, timezone
Expand Down Expand Up @@ -120,6 +120,9 @@ async def on_member_join(self, member: discord.Member) -> None:
self.last30pfps.append(this_hash)
if len(self.last30pfps) > 30:
del self.last30pfps[0]

with open("./bot_data/last30pfps.json", "w") as f:
json.dump(self.last30pfps, f)

# if ratelimit is triggered, we should ban all the users that joined in the past 8 seconds
if join_spam_detection_bucket.update_rate_limit(current):
Expand Down Expand Up @@ -316,6 +319,7 @@ async def ping_spam(self, message: discord.Message):

# await mute(ctx, user, mod=ctx.guild.me, reason="Ping spam")
await user.timeout(twoweek, reason="Ping spam")
await report_spam(self.bot, message, user, "Ping spam")
return True

return False
Expand Down Expand Up @@ -345,6 +349,7 @@ async def message_spam(self, message: discord.Message):
twoweek = datetime.now() + timedelta(days=14)

await user.timeout(twoweek, reason="Message spam")
await report_spam(self.bot, message, user, "Message spam")
return True

return False
Expand Down Expand Up @@ -378,47 +383,19 @@ async def raid_ban(self, user: discord.Member, reason="Raid phrase detected", dm
"""Helper function to ban users"""

async with self.banning_lock:
# if self.ban_user_mapping.get(user.id) is not None:
if self.bot.ban_cache.is_banned(user.id):
return
else:
self.bot.ban_cache.ban(user.id)

db_guild = guild_service.get_guild()

infraction = Infraction(
_id=db_guild.infraction_id,
_type="BAN",
date=datetime.now(),
mod_id=self.bot.user.id,
mod_tag=str(self.bot.user),
punishment="PERMANENT",
reason=reason
)

guild_service.inc_infractionid()
user_service.add_infraction(user.id, infraction)

log = prepare_ban_log(self.bot.user, user, infraction)

if dm_user:
try:
await user.send(f"You were banned from {user.guild.name}.\n\nThis action was performed automatically. If you think this was a mistake, please send a message here: https://www.reddit.com/message/compose?to=%2Fr%2Fpalera1n", embed=log)
await user.send(f"You were banned from {user.guild.name}.\n\nThis action was performed automatically.")
except Exception:
pass

if user.guild.get_member(user.id) is not None:
await user.ban(reason="Raid")
await user.ban(reason=reason)
else:
await user.guild.ban(discord.Object(id=user.id), reason="Raid")

public_logs = user.guild.get_channel(db_guild.channel_public)
if public_logs:
log.remove_author()
log.set_thumbnail(url=user.display_avatar)
await public_logs.send(embed=log)
await user.guild.ban(discord.Object(id=user.id), reason=reason)

async def freeze_server(self, guild):
async def freeze_server(self, guild: discord.Guild):
"""Freeze all channels marked as freezeable during a raid, meaning only people with the Member+ role and up
can talk (temporarily lock out whitenames during a raid)"""

Expand Down
26 changes: 0 additions & 26 deletions bridget/utils/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,6 @@ async def manual_report(mod: discord.Member, target: Union[discord.Message, disc
embed = prepare_embed(target, title="A moderator reported a member")
await channel.send(ping_string, embed=embed, view=view, allowed_mentions=discord.AllowedMentions(everyone=False, users=True, roles=True))

async def mempro_report(genius: discord.Member, target: Union[discord.Message, discord.Member] = None):
"""Deals with a report
Parameters
----------
bot : discord.Client
"Bot object"
message : discord.Message
"Filtered message"
genius : discord.Member
"The genius that started this report
"""
db_guild = guild_service.get_guild()
channel = target.guild.get_channel(db_guild.channel_mempro_reports)

ping_string = f"{genius.mention} reported a member"
if isinstance(target, discord.Message):
view = ReportActions(target.author)
else:
view = ReportActions(target)

embed = prepare_embed(target, title="A user reported a member")
await channel.send(ping_string, embed=embed, view=view, allowed_mentions=discord.AllowedMentions(everyone=False, users=True, roles=True))


async def report_raid_phrase(bot: discord.Client, message: discord.Message, domain: str):
"""Deals with a report
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
restart: always
ports:
- 8096:8096
volumes:
- ./bot_data:/app/bot_data
# network_mode: host # comment this out if you want to use dockerized mongo
# also, if you want to use dockerized Mongo you need to change DB_HOST to "mongo" in .env

Expand Down

0 comments on commit 6ee9b06

Please sign in to comment.