Skip to content

Commit

Permalink
[Fix] Use correct highscore column, add custom emoji (#16)
Browse files Browse the repository at this point in the history
* update for custom emoji

Signed-off-by: Erin Atkinson <[email protected]>

* fix typo on db query

Signed-off-by: Erin Atkinson <[email protected]>

---------

Signed-off-by: Erin Atkinson <[email protected]>
  • Loading branch information
erindatkinson authored Oct 5, 2023
1 parent 5a5f414 commit bb8b067
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions docker-compose.override.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
BOT_LOG_LEVEL: INFO
BOT_DATABASE: data/snowball.db
BOT_DISCORD_CHANNEL: approved-channel
BOT_DISCORD_RESET_EMOJI: negative_squared_cross_mark
BOT_DISCORD_ADMIN_GUILD: id-for-admin-server
BOT_DISCORD_ADMIN_ROLE: id-for-admin-role
BOT_DISCORD_APP_KEY: app-id
Expand Down
1 change: 1 addition & 0 deletions packages/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def init()->(Configs|Exception):
parser.bind("app_key", "discord")
parser.bind("public_key", "discord")
parser.bind("token", "discord")
parser.bind("reset_emoji", "discord")
data = parser.parse()
configs = Configs(data)
init_logs(configs.get("name"), configs.get("log_level"))
Expand Down
2 changes: 1 addition & 1 deletion packages/config/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def increment_count(self, external_id:str, user:str, count:int):
query = """UPDATE servers
SET count = ?,
count_user = ?,
highscore = CASE WHEN high_score < ? THEN ? ELSE highs_core END
high_score = CASE WHEN high_score < ? THEN ? ELSE high_score END
WHERE external_id = ?;"""
with closing(self.conn.cursor()) as cur:
cur.execute(query, (count, user, count, count, external_id, ))
Expand Down
16 changes: 12 additions & 4 deletions packages/services/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, configs, intents: Intents):
self._lock = Lock()
self.configs = configs
self.db_conn = Database(configs.get("database"))
self.emoji_string = ""
super().__init__(intents=intents)

async def on_ready(self):
Expand All @@ -23,6 +24,12 @@ async def on_ready(self):
guilds = [guild async for guild in self.fetch_guilds()]
for guild in guilds:
self.db_conn.initialize_server(str(guild.id), "discord")

emoji_name = self.configs.get("reset_emoji", "discord")
for emoji in await guild.fetch_emojis():
if emoji.name == emoji_name:
self.emoji_string = str(emoji)

channels = await guild.fetch_channels()
for channel in channels:
if channel.name == self.configs.get("channel", "discord"):
Expand All @@ -36,7 +43,7 @@ async def __check_commands(self, message:Message)->bool:
commands = {
"!commands": "",
"!help": help_string,
"!highscore": "Your server highscore is:"
"!highscore": "Your server highscore is: "
}

# this has to be done outside of the dict initialzation
Expand All @@ -52,7 +59,7 @@ async def __check_commands(self, message:Message)->bool:
if reply is not None:
# TODO: wrap highscore in its own function that only would get called if match.
if reply.startswith("Your server"):
reply = reply + self.db_conn.get_highscore(str(message.guild.id))
reply = reply + str(self.db_conn.get_highscore(str(message.guild.id)))
await message.reply(reply)
return True
return False
Expand Down Expand Up @@ -82,7 +89,8 @@ async def on_message(self, message:Message):
if this_count == -1:
self.db_conn.reset_count(str(message.guild.id))
await message.add_reaction('❎')
await message.channel.send('the cycle begins anew')

await message.channel.send(f"{self.emoji_string} The cycle begins anew")
elif this_count == count + 1:
self.db_conn.increment_count(
str(message.guild.id),
Expand All @@ -92,7 +100,7 @@ async def on_message(self, message:Message):
else:
self.db_conn.reset_count(str(message.guild.id))
await message.add_reaction('❎')
await message.channel.send('the cycle begins anew')
await message.channel.send(f"{self.emoji_string} The cycle begins anew")
self._lock.release()
else:
await message.add_reaction('🌨')
Expand Down

0 comments on commit bb8b067

Please sign in to comment.