Skip to content

Commit

Permalink
Update version to 2.0.0 and refactor DontPingStaff class
Browse files Browse the repository at this point in the history
  • Loading branch information
sravan1946 committed Mar 5, 2024
1 parent 838ff75 commit c1b366f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Once the bot is installed, run the following command in Discord:
| Acromania | 1.2.0 | <details><summary>Acronym game.</summary>Acronym game is a fun and engaging word game where players take turns creating a phrase or sentence from a series of letters, with each letter representing a word in the phrase.</details> | sravan |
| Aki | 1.2.1 | <details><summary>Play Akinator in Discord!</summary>Play Akinator in Discord!</details> | PhenoM4n4n and sravan |
| AltDentifier | 2.0.0 | <details><summary>Check users with AltDentifier API</summary>Check users with AltDentifier API</details> | PhenoM4n4n |
| DontPingStaff | 1.4.0 | <details><summary>Take actions on users who ping</summary>Punish the users who ping others with a certain role</details> | sravan |
| DontPingStaff | 2.0.0 | <details><summary>Take actions on users who ping</summary>Punish the users who ping others with a certain role</details> | sravan |
| ForceMention | 1.0.1 | <details><summary>Mention unmentionables</summary>Mentions roles that are unmentionable</details> | Bobloy, PhenoM4n4n, and sravan |
| GuessTheNumber | 1.3.0 | <details><summary>A simple gtn game</summary>A guess the number game which you can play in discord</details> | sravan |
| HidePing | 1.1.0 | <details><summary>Hidden mentions</summary>Mentions the user in a hidden ping</details> | sravan |
Expand Down
80 changes: 43 additions & 37 deletions dps/dps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, bot: Red) -> None:
self.cache = {}

__author__ = ["sravan"]
__version__ = "1.4.0"
__version__ = "2.0.0"

def format_help_for_context(self, ctx: commands.Context) -> str:
"""
Expand Down Expand Up @@ -637,46 +637,52 @@ async def check_ping(self, message: discord.Message):
staff_role = await self.config.guild(guild).staff_role()
mes = await self.config.guild(guild).message()
action = await self.config.guild(guild).action()
for mentions in message.mentions:
pings = [mentions.id]
for ping in pings:
member = guild.get_member(int(ping))
if member.id == message.author.id:
continue
for role in member.roles:
if role.id in staff_role:
if author.id not in self.cache:
for member in message.mentions:
if member.id == message.author.id:
continue
for role in member.roles:
if role.id in staff_role:
if self.config_cache[guild.id]["amount"] == 1:
if action is None:
return
return await self.take_action(action, message)
if author.id not in self.cache:
self.cache[author.id] = {"count": 1, "time": now}
await message.reply(mes)
else:
if now - self.cache[author.id]["time"] > timedelta(
seconds=self.config_cache[guild.id]["per"]
):
self.cache[author.id] = {"count": 1, "time": now}
await message.reply(mes)
return
self.cache[author.id]["count"] += 1
if (
self.cache[author.id]["count"]
< self.config_cache[guild.id]["amount"]
):
await message.reply(mes)
else:
if now - self.cache[author.id]["time"] > timedelta(
seconds=self.config_cache[guild.id]["per"]
):
self.cache[author.id] = {"count": 1, "time": now}
await message.reply(mes)
self.cache[author.id]["count"] = 0
if action is None:
return
self.cache[author.id]["count"] += 1
if (
self.cache[author.id]["count"]
< self.config_cache[guild.id]["amount"]
):
await message.reply(mes)
else:
self.cache[author.id]["count"] = 0
if action is None:
return
elif action == "mute":
await self.mute(message)
elif action == "kick":
await self.kick(message)
elif action == "ban":
await self.ban(message)
elif action == "addroles":
await self.addrole(message)
elif action == "removeroles":
await self.removerole(message)
break
break
await self.take_action(action, message)
break

async def take_action(self, action: str, message: discord.Message):
"""
Take action on a member.
"""
if action == "mute":
await self.mute(message)
elif action == "kick":
await self.kick(message)
elif action == "ban":
await self.ban(message)
elif action == "addroles":
await self.addrole(message)
elif action == "removeroles":
await self.removerole(message)

async def mute(self, message: discord.Message):
"""
Expand Down

0 comments on commit c1b366f

Please sign in to comment.