Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 8471e12

Browse files
committed
Fixed spam on join and added some shorthands
1 parent ed1dc4f commit 8471e12

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

extensions/events/on_member_join.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@ def __init__(self, client: Client) -> None:
1313

1414
@commands.Cog.listener()
1515
async def on_member_join(self, member: discord.Member):
16+
17+
commands_channel = member.guild.get_channel(settings.COMMANDS_CHANNEL)
18+
19+
if not commands_channel:
20+
return # to prevent other servers using spam on join
21+
22+
spam_on_join = self.client.db.get(f'{member.id}.spam_on_join') or {}
23+
protection = self.client.db.get(f"{member.id}.protected")
24+
if protection: return
1625
if self.client.db.get('spam_on_join_all'):
17-
cmds_channel = self.client.get_channel(settings.COMMANDS_CHANNEL)
18-
await cmds_channel.send(f'Spam all on join is enabled')
26+
# await cmds_channel.send(f'Spam all on join is enabled')
1927
try:
2028
await member.send("🥱 SEXED BY SPAM ALL ON JOIN")
21-
2229
msg = "{}: {}".format('Zena Bot', 'sexed by spam all on join')[:1500:]
23-
2430
Tools.send_direct_message(member.id, msg)
25-
26-
await cmds_channel.send(f'{member} got spammed on joining')
31+
await commands_channel.send(f'{member} got spammed on joining')
32+
if spam_on_join.get("status"):
33+
self.client.db.delete(f'{member.id}.spam_on_join')
2734
except:
28-
await cmds_channel.send(f'Ummm, I got an error while spamming {member} upon joining')
29-
30-
else:
31-
spam_on_join = self.client.db.get(f'{member.id}.spam_on_join')
32-
if spam_on_join and spam_on_join['status']:
33-
cmds_channel = self.client.get_channel(settings.COMMANDS_CHANNEL)
34-
await cmds_channel.send(f'{member} has spam on join enabled')
35-
try:
36-
await member.send("🥱 SEXED BY %s" % spam_on_join['initiator'])
35+
await commands_channel.send(f'Ummm, I got an error while spamming {member} upon joining')
3736

38-
msg = "{}: {}".format(spam_on_join['initiator'], 'sexed by spam on join')[:1500:]
39-
40-
Tools.send_direct_message(member.id, msg)
41-
42-
await cmds_channel.send(f'{member} got spammed on joining')
43-
self.client.db.delete(f'{member.id}.spam_on_join')
44-
except:
45-
await cmds_channel.send(f'Ummm, I got an error while spamming {member} upon joining')
46-
self.client.db.delete(f'{member.id}.spam_on_join')
37+
elif spam_on_join.get('status'):
38+
await commands_channel.send(f'{member} has spam on join enabled')
39+
try:
40+
await member.send("🥱 SEXED BY %s" % spam_on_join['initiator'])
41+
msg = "{}: {}".format(spam_on_join['initiator'], 'sexed by spam on join')[:1500:]
42+
Tools.send_direct_message(member.id, msg)
43+
await commands_channel.send(f'{member} got spammed on joining')
44+
self.client.db.delete(f'{member.id}.spam_on_join')
45+
except:
46+
await commands_channel.send(f'Ummm, I got an error while spamming {member} upon joining')
4747

4848

4949

extensions/messages/spam.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ async def onjoin(self, ctx: commands.Context): ...
4747
async def add(self, ctx: commands.Context, user: discord.User):
4848
if ctx.channel.id != settings.COMMANDS_CHANNEL: return await ctx.reply("The commands are only available at <#%s>" % settings.COMMANDS_CHANNEL)
4949

50-
current_status = self.client.db.get(f'{user.id}.spam_on_join')
50+
current_status = self.client.db.get(f'{user.id}.spam_on_join') or {}
5151

52-
if current_status and current_status['status']:
52+
if current_status.get("status"):
5353
await ctx.reply(f'{user} is already in the spam_on_join list')
5454
else:
5555
json = {
@@ -63,10 +63,10 @@ async def add(self, ctx: commands.Context, user: discord.User):
6363
async def remove(self, ctx: commands.Context, user: discord.User):
6464
if ctx.channel.id != settings.COMMANDS_CHANNEL: return await ctx.reply("The commands are only available at <#%s>" % settings.COMMANDS_CHANNEL)
6565

66-
current_status = self.client.db.get(f'{user.id}.spam_on_join')
66+
current_status = self.client.db.get(f'{user.id}.spam_on_join') or {}
6767

68-
if current_status and current_status['status']:
69-
if current_status['initiator'] != ctx.author.id:
68+
if current_status.get("status"):
69+
if current_status.get("initiator") != ctx.author.id:
7070
await ctx.reply(f'Only {current_status["initiator"]} can remove {user} from the spam on join list')
7171
else:
7272
self.client.db.delete(f'{user.id}.spam_on_join')
@@ -75,7 +75,7 @@ async def remove(self, ctx: commands.Context, user: discord.User):
7575
@commands.is_owner()
7676
async def all(self, ctx: commands.Context):
7777
current_status = self.client.db.get(f'spam_on_join_all')
78-
status = False if current_status else True
78+
status = not bool(current_status)
7979

8080
self.client.db.set(f'spam_on_join_all', status)
8181

0 commit comments

Comments
 (0)