diff --git a/compose.yaml.prod b/compose.yaml.prod index bb99adb..59fe183 100644 --- a/compose.yaml.prod +++ b/compose.yaml.prod @@ -10,7 +10,7 @@ services: - DB_HOST=mongodb - DB_USERNAME=${DB_USERNAME} - DB_PASSWORD=${DB_PASSWORD} - + mongodb: image: mongo restart: always diff --git a/py/bin/storage.py b/py/bin/storage.py index a3f5163..650ff55 100644 --- a/py/bin/storage.py +++ b/py/bin/storage.py @@ -1,21 +1,10 @@ class storage: def __init__(self, serverid, db): self.serverdb = db[str(serverid)] - self.defaultdb = db["default"] def db(self, module, key, value=None): - r = self.serverdb.find_one({"module": module})[key] + try : r = self.serverdb.find_one({"module": module}).get(key) + except AttributeError: r = None if value is not None: - self.serverdb.update_one({"module": module}, {"$set": {key: value}}) - return r - - def update_guild(self): - for doc in self.defaultdb.find(): - existing_doc = self.serverdb.find_one({"module": doc["module"]}) - if existing_doc: - for key, value in doc.items(): - if key not in existing_doc: - existing_doc[key] = value - self.serverdb.replace_one({"module": doc["module"]}, existing_doc) - else: - self.serverdb.insert_one(doc) \ No newline at end of file + self.serverdb.update_one({"module": module}, {"$set": {key: value}}, upsert=True) + return r \ No newline at end of file diff --git a/py/bot.py b/py/bot.py index 2cbc03f..be0df28 100644 --- a/py/bot.py +++ b/py/bot.py @@ -27,11 +27,10 @@ async def on_ready(): print("Logged in as") print(bot.user.name) print(bot.user.id) - print("------") - logging.info(f"Logged in as {bot.user} (ID: {bot.user.id})") - for guild in bot.guilds: - logging.info(f"Added {guild.name} (ID: {guild.id})") - storage(guild.id, bot.db).update_guild() + # logging.info(f"Logged in as {bot.user} (ID: {bot.user.id})") + # for guild in bot.guilds: + # logging.info(f"Added {guild.name} (ID: {guild.id})") + # storage(guild.id, bot.db).update_guild() bot.run(env["BOT_TOKEN"]) \ No newline at end of file diff --git a/py/cogs/counting.py b/py/cogs/counting.py index e0066e1..4698218 100644 --- a/py/cogs/counting.py +++ b/py/cogs/counting.py @@ -8,8 +8,7 @@ class Counting(commands.Cog): @commands.Cog.listener() async def on_message(self, message): db = storage(message.guild.id, self.bot.db).db - count = int(db('counting', 'count')) - print(count, message.content[0]) + count = int(db('counting', 'count') or 0) if message.author.bot or message.channel.id != db('counting', 'channel') or not message.content.isdigit(): return @@ -30,7 +29,7 @@ class Counting(commands.Cog): async def channel(self, ctx): db = storage(ctx.guild.id, self.bot.db).db db('counting', 'channel', ctx.channel.id) - await ctx.send("counting channel set") + await ctx.send(f"counting channel set to {db('counting', 'channel')}")