Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
howardt12345 committed Oct 10, 2023
1 parent 886473b commit e9afaf3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
27 changes: 27 additions & 0 deletions commands/meow/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from re import compile, IGNORECASE, UNICODE

KEYWORDS_MEOW = (
'meow',
'喵'
)

MEOW = '喵'
TRADITIONAL_CAT = '貓'

POSSIBLE_MEOW_REACTS = [
'<a:catArrive:1161441364869918881>',
'<:Capoo:1139357657698938991>'
]
POSSIBLE_MEOW_MESSAGES = [
MEOW,
TRADITIONAL_CAT,
'瞄',
'貓子孩女'
'錨'
] + POSSIBLE_MEOW_REACTS


MEOW_REGEX = compile(
rf"\b(?:{'|'.join(KEYWORDS_MEOW)})",
flags=IGNORECASE | UNICODE,
)
47 changes: 47 additions & 0 deletions commands/meow/meow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from random import choice, randint, shuffle
import discord

from commands.modules.probability import mock_bernoulli
from .consts import MEOW, MEOW_REGEX, POSSIBLE_MEOW_MESSAGES, POSSIBLE_MEOW_REACTS, TRADITIONAL_CAT


def is_meow_message(message: discord.Message):
return MEOW_REGEX.search(message.content)


def is_traditional_cat(message: discord.Message):
return TRADITIONAL_CAT in message.content


def from_meow_channel(message: discord.Message):
return MEOW in message.channel.name


async def do_meow(message: discord.Message, mention_author=False, multiplier=1):
await message.reply(MEOW * multiplier, mention_author=mention_author)
if not mention_author and mock_bernoulli(0.25):
await message.channel.send(choice(POSSIBLE_MEOW_MESSAGES))


async def react_meow(message: discord.Message):
shuffle(POSSIBLE_MEOW_REACTS)
for react in POSSIBLE_MEOW_REACTS:
if mock_bernoulli(0.5):
await message.add_reaction(react)


async def meow_meow(message: discord.Message):
if is_meow_message(message):
await react_meow(message)

if is_traditional_cat(message):
await do_meow(message, multiplier=randint(2, 101))
elif is_meow_message(message) and mock_bernoulli(0.169):
await do_meow(message)
elif from_meow_channel(message):
if not is_meow_message(message) and mock_bernoulli(0.5):
await do_meow(message, True)
elif mock_bernoulli(0.25):
await do_meow(message, False)
elif mock_bernoulli(0.001):
await do_meow(message)
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from commands.fetch_entry import fetch_entry_cmd
from commands.fetch_entry import fetch_entry_ui
from commands.edit_entry import edit_entry_cmd
from commands.meow.meow import meow_meow
from commands.one_o_one import one_o_one
from commands import hgs
from commands.reacttw import react_tw
Expand Down Expand Up @@ -129,5 +130,6 @@ async def on_message(message: discord.Message):
if hsinchu_wind.is_hsinchu_message(message):
await hsinchu_wind.send_hsinchu_msg(message)

await meow_meow(message)

client.run(TOKEN)

0 comments on commit e9afaf3

Please sign in to comment.