Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot mention #48

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
from commands.restart import restart
from commands.gothefucktosleep import gothefucktosleep
from commands.boba import boba

from commands.confessions import confession

from presence import watching

from mentioned import mention_responses

from commands.modules.supabase import supabaseClient
from commands.modules import config
import bot
Expand Down Expand Up @@ -117,41 +120,45 @@ async def on_message(message: discord.Message):

events = []

if client.user.mentioned_in(message): # if bot is pinged in message
await mention_responses.reply_with_random_response(message)
events.append("pinged")

if react_tw.is_TW_message(message):
try:
await react_tw.send_react_tw(message)
except Exception as e:
print('failed to react Taiwan: ', e)
print("failed to react Taiwan: ", e)
events.append("tw")
if react_hgs.is_hgs_message(message):
try:
await react_hgs.send_react_hgs(message)
except Exception as e:
print('failed to react HGS: ', e)
print("failed to react HGS: ", e)
events.append("hgs")
if react_baltics.is_baltic_message(message):
try:
await react_baltics.send_react_baltic(message)
except Exception as e:
print('failed to react Baltics: ', e)
print("failed to react Baltics: ", e)
events.append("baltics")
if react_czech.is_czech_message(message):
try:
await react_czech.send_react_czech(message)
except Exception as e:
print('failed to react Czech: ', e)
print("failed to react Czech: ", e)
events.append("czech")
if react_ph.is_ph_message(message):
try:
await react_ph.send_react_ph(message)
except Exception as e:
print('failed to react PH: ', e)
print("failed to react PH: ", e)
events.append("ph")
if react_ua.is_UA_message(message):
try:
await react_ua.send_react_ua(message)
except Exception as e:
print('failed to react UA: ', e)
print("failed to react UA: ", e)
events.append("ua")

if hsinchu_wind.is_hsinchu_message(message):
Expand All @@ -164,6 +171,7 @@ async def on_message(message: discord.Message):
if len(events) > 0:
await logging.log_message_event(message, events)


@client.event
async def on_guild_join(guild):
await tree.sync(guild=guild)
Expand All @@ -174,4 +182,5 @@ async def on_guild_join(guild):
}
).execute()


client.run(TOKEN)
29 changes: 29 additions & 0 deletions mentioned/mention_responses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import random
import discord

# a dict of possible responses and their weights when the bot is mentioned.
POSSIBLE_RESPONSES_MAP = {
"<:BocchiPing:1170161488812593172>": 5,
"<:uwu:1161126694762061825>": 3,
"<a:catArrive:1161441364869918881>": 3,
"<:ChisobCat:1157361078452375582>": 2,
"<:Black_Bear:1132603463126237244>": 1,
"<:101_Top:1132608896222113951>\n<:101_Floor:1132608196515725332>": 1,
"<:PineappleCake:1156373382565212323>": 1,
"<:slipper:1132961055304323143>": 1,
"喵": 1,
"🧋": 1,
}
RESPONSES = list(POSSIBLE_RESPONSES_MAP.keys())
WEIGHTS = list(POSSIBLE_RESPONSES_MAP.values())


def get_random_response() -> str:
# ^ could also change k in the future to be a random number
response = random.choices(RESPONSES, weights=WEIGHTS, k=1)[0]
return response


async def reply_with_random_response(message: discord.Message):
response = get_random_response()
await message.reply(response)