mirror of
https://github.com/UiO-Gaming/mustafa.git
synced 2026-11-05 13:56:48 +01:00
clean up /mock logic
This commit is contained in:
1 file changed
+13
-18
+13
-18
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import itertools
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -200,7 +201,7 @@ class Misc(commands.Cog):
|
|||||||
@app_commands.describe(text="Teksten som skal mockes", user="Brukeren som skal mockes")
|
@app_commands.describe(text="Teksten som skal mockes", user="Brukeren som skal mockes")
|
||||||
async def mock(
|
async def mock(
|
||||||
self,
|
self,
|
||||||
interation: discord.Interaction,
|
interaction: discord.Interaction,
|
||||||
text: app_commands.Range[str, 1, 4096],
|
text: app_commands.Range[str, 1, 4096],
|
||||||
user: discord.User | None = None,
|
user: discord.User | None = None,
|
||||||
):
|
):
|
||||||
@@ -210,28 +211,22 @@ class Misc(commands.Cog):
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
interaction (discord.Interaction): Slash command context object
|
interaction (discord.Interaction): Slash command context object
|
||||||
text (str): Text to clapify
|
text (str): Text to mock
|
||||||
|
user (discord.User | None): User to mention in the reply
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: make this not horrible. I can't be botherd to right now
|
def mock_word(word: re.Match) -> str:
|
||||||
words = text.split(" ")
|
letters = itertools.count()
|
||||||
for i, word in enumerate(words):
|
return "".join(
|
||||||
karakter = 0
|
(char.upper() if next(letters) % 2 else char.lower()) if char.isalpha() else char
|
||||||
word = list(word)
|
for char in word.group()
|
||||||
for j, char in enumerate(word):
|
)
|
||||||
if char.isalpha():
|
|
||||||
if karakter % 2 == 0:
|
|
||||||
word[j] = char.lower()
|
|
||||||
else:
|
|
||||||
word[j] = char.upper()
|
|
||||||
karakter += 1
|
|
||||||
words[i] = "".join(word)
|
|
||||||
|
|
||||||
text = " ".join(words)
|
text = re.sub(r"\S+", mock_word, text)
|
||||||
mention = user.mention if user else ""
|
mention = user.mention if user else ""
|
||||||
|
|
||||||
embed = discord.Embed(color=interation.client.user.color, description=text)
|
embed = discord.Embed(color=interaction.client.user.color, description=text)
|
||||||
await interation.response.send_message(content=mention, embed=embed)
|
await interaction.response.send_message(content=mention, embed=embed)
|
||||||
|
|
||||||
@app_commands.checks.bot_has_permissions(embed_links=True)
|
@app_commands.checks.bot_has_permissions(embed_links=True)
|
||||||
@app_commands.checks.cooldown(1, 5)
|
@app_commands.checks.cooldown(1, 5)
|
||||||
|
|||||||
Reference in new issue
Block a user