Skip to content

Commit

Permalink
Add lock buffer and bugfixes (#32)
Browse files Browse the repository at this point in the history
* * update lock buffer
* fix off by one template

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

* make the hold configurable

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

---------

Signed-off-by: Erin Atkinson <[email protected]>
  • Loading branch information
erindatkinson authored Apr 24, 2024
1 parent c35ac0b commit 2d51a85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions docker-compose.override.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ services:
BOT_DISCORD_APP_KEY: app-id
BOT_DISCORD_PUBLIC_KEY: public-key
BOT_DISCORD_TOKEN: sdk.token
BOT_DISCORD_MUTEX_HOLD: 2
8 changes: 6 additions & 2 deletions packages/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
from packages.expectenv.expectenv import ExpectEnvParser
from .logging import init_logs


class Configs:
"""class to manage the various configs for the app"""

def __init__(self, configs):
self.configs = configs

def get(self, key, namespace=None)->str:
def get(self, key, namespace=None) -> str:
"""get pulls a key from a namespace or raises a KeyError if not found"""
if namespace is None:
return self.configs["core"][key]
return self.configs[namespace][key]

def init()->(Configs|Exception):

def init() -> Configs | Exception:
"""initializes the configuration for the bot"""
parser = ExpectEnvParser("bot")
parser.bind("name")
Expand All @@ -27,6 +30,7 @@ def init()->(Configs|Exception):
parser.bind("public_key", "discord")
parser.bind("token", "discord")
parser.bind("reset_emoji", "discord")
parser.bind("mutex_hold", "discord")
data = parser.parse()
configs = Configs(data)
init_logs(configs.get("name"), configs.get("log_level"))
Expand Down
5 changes: 3 additions & 2 deletions packages/services/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def on_message(self, message: Message):
await message.add_reaction("❎")
await message.channel.send(
reset_string.format(
count=count,
count=count + 1,
this_count=this_count,
emoji_string=self.emoji_string,
)
Expand All @@ -115,14 +115,15 @@ async def on_message(self, message: Message):
await message.add_reaction("❎")
await message.channel.send(
reset_string.format(
count=count,
count=count + 1,
this_count=this_count,
emoji_string=self.emoji_string,
)
)
except Exception as e:
logging.error(e)
finally:
sleep(float(self.configs.get("mutex_hold", "discord")))
self._lock.release()
else:
await message.add_reaction("🌨")
Expand Down

0 comments on commit 2d51a85

Please sign in to comment.