mirror of
https://github.com/UiO-Gaming/mustafa.git
synced 2026-11-05 13:56:48 +01:00
add funreply chance parameter
This commit is contained in:
1 file changed
+13
-10
+13
-10
@@ -1,3 +1,4 @@
|
||||
import random
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
@@ -48,28 +49,29 @@ class FunReplies(commands.Cog):
|
||||
# TODO: add ability to disable single triggers?
|
||||
# Auto assign cooldown_key?
|
||||
triggers = [
|
||||
(r"(^|\W)borgerlønn(\W|$)", "@ sivert DE SNAKKER OM BORGERLØNN", "borgerlønn"),
|
||||
(r"(^|\W)olof palme(\W|$)", "Jeg vet hvem som drepte Olof Palme 👀", "olof palme"),
|
||||
(r"(^|\W)+ye+et($|\W)+", "<:Nei:826593267642662912>", "yeet"),
|
||||
(r"(^|\W)borgerlønn(\W|$)", "@ sivert DE SNAKKER OM BORGERLØNN", "borgerlønn", 50),
|
||||
(r"(^|\W)olof palme(\W|$)", "Jeg vet hvem som drepte Olof Palme 👀", "olof palme", 100),
|
||||
(r"(^|\W)+ye+et($|\W)+", "<:Nei:826593267642662912>", "yeet", 100),
|
||||
(
|
||||
r"(^|\W)skal? aldri drikke?[\w\s]*igjen($|\W)+",
|
||||
":billed_cap:\nhttps://cdn.discordapp.com/attachments/811606213665357824/1320756460321378396/v15044gf0000ctk1refog65kh5pqtpkg.mov",
|
||||
"drikke",
|
||||
75
|
||||
),
|
||||
(r"(^|\W)(jeg?|(e|æ)(g|j)?|i) er? sivert arntzen($|\W)+", "Nei, jeg er Sivert Arntzen!", "sivert"),
|
||||
(r"(^|\W)bærum(\W|$)", "Sa noen Bærum? 👀🍾 <@205741213050077185>", "bærum"),
|
||||
(r"(^|\W)ost(\W|$)", "Lol, Robert ost🧀", "ost"),
|
||||
(r"(^|\W)(jeg?|(e|æ)(g|j)?|i) er? sivert arntzen($|\W)+", "Nei, jeg er Sivert Arntzen!", "sivert", 100),
|
||||
(r"(^|\W)bærum(\W|$)", "Sa noen Bærum? 👀🍾 <@205741213050077185>", "bærum", 50),
|
||||
(r"(^|\W)ost(\W|$)", "Lol, Robert ost🧀", "ost", 10),
|
||||
]
|
||||
|
||||
for trigger in triggers:
|
||||
regex, reply, cooldown_key = trigger
|
||||
regex, reply, cooldown_key, chance = trigger
|
||||
if await self.trigger(
|
||||
message=message, regex_match=regex, reply=reply, cooldown_key=cooldown_key, regex_flags=re.IGNORECASE
|
||||
message=message, regex_match=regex, reply=reply, cooldown_key=cooldown_key, regex_flags=re.IGNORECASE, trigger_chance=chance
|
||||
):
|
||||
return
|
||||
|
||||
async def trigger(
|
||||
self, message: discord.Message, regex_match: str, reply: str, cooldown_key: str, regex_flags=None
|
||||
self, message: discord.Message, regex_match: str, reply: str, cooldown_key: str, regex_flags=None, trigger_chance: int = 100
|
||||
) -> bool:
|
||||
"""
|
||||
Add a trigger to the bot
|
||||
@@ -81,6 +83,7 @@ class FunReplies(commands.Cog):
|
||||
reply (str): The reply to send
|
||||
cooldown_key (str): The key to use for cooldown tracking
|
||||
regex_flags (int): The regex flags to use
|
||||
trigger_chance (int): The chance of the trigger being executed
|
||||
|
||||
Returns
|
||||
----------
|
||||
@@ -90,7 +93,7 @@ class FunReplies(commands.Cog):
|
||||
if (datetime.now() - self.previous_invokations[cooldown_key]).seconds < self.cooldown_seconds:
|
||||
return False
|
||||
|
||||
if re.search(regex_match, message.content, flags=regex_flags):
|
||||
if re.search(regex_match, message.content, flags=regex_flags) and random.randint(1, 100) <= trigger_chance:
|
||||
await message.reply(reply)
|
||||
self.previous_invokations[cooldown_key] = datetime.now()
|
||||
return True
|
||||
|
||||
Reference in new issue
Block a user