From 0823552a2d465acd3273ccaf19157b5d913ecd2a Mon Sep 17 00:00:00 2001 From: Ian Burgess Date: Wed, 19 Jun 2024 22:22:21 -0600 Subject: [PATCH] stable --- bin/storage.py | 4 ++-- bot.py | 2 ++ cogs/counting.py | 22 +++++++++++----------- cogs/misc.py | 6 +++++- cogs/triggers.py | 8 ++++---- compose/compose-dev.yaml | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 compose/compose-dev.yaml diff --git a/bin/storage.py b/bin/storage.py index 5e2d4c0..6237bac 100644 --- a/bin/storage.py +++ b/bin/storage.py @@ -2,9 +2,9 @@ class storage: def __init__(self, server_id, db): self.server_id = str(server_id) self.db = db - self.collection = db['turdbot'] # Replace with your actual collection name + self.collection = db['turdbot'] - async def db(self, module, key=None, value=None): + async def store(self, module, key=None, value=None): document = await self.collection.find_one({"server_id": self.server_id}) if not document: diff --git a/bot.py b/bot.py index 2cb550b..3148eae 100644 --- a/bot.py +++ b/bot.py @@ -16,6 +16,7 @@ bot = bridge.Bot( bot.load_extension("cogs.triggers") bot.load_extension("cogs.counting") bot.load_extension("cogs.settings") +bot.load_extension("cogs.misc") uri = f"mongodb://{env['DB_USERNAME']}:{env['DB_PASSWORD']}@{env['DB_HOST']}/?authSource=admin" bot.db = MongoClient(uri)["turdbot"] @@ -27,6 +28,7 @@ async def on_ready(): print("Logged in as") print(bot.user.name) print(bot.user.id) + print(bot.version) print("------") bot.run(env["BOT_TOKEN"]) \ No newline at end of file diff --git a/cogs/counting.py b/cogs/counting.py index e07db2d..4b7bcab 100644 --- a/cogs/counting.py +++ b/cogs/counting.py @@ -7,34 +7,34 @@ 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') or 0) + store = storage(message.guild.id, self.bot.db).store + count = int(await store('counting', 'count') or 0) - if message.author.bot or message.channel.id != db('counting', 'channel') or not message.content.isdigit(): + if message.author.bot or message.channel.id != await store('counting', 'channel') or not message.content.isdigit(): return - elif message.author.id == db('counting', 'user'): + elif message.author.id == await store('counting', 'user'): await message.reply(f"you done fucked up there chief, you cant count twice") elif str(count+1) != message.content: await message.reply(f"you done fucked up there chief, count was {count}") else: - db('counting', 'count', count+1) - db('counting', 'user', message.author.id) + await store('counting', 'count', count+1) + await store('counting', 'user', message.author.id) await message.add_reaction('✅') @bridge.bridge_command() async def channel(self, ctx): - db = storage(ctx.guild.id, self.bot.db).db - db('counting', 'channel', ctx.channel.id) - await ctx.send(f"counting channel set to {db('counting', 'channel')}") + store = storage(ctx.guild.id, self.bot.db).store + await store('counting', 'channel', ctx.channel.id) + await ctx.send(f"counting channel set to {store('counting', 'channel')}") @bridge.bridge_command() async def setcount(self, ctx, args): - db = storage(ctx.guild.id, self.bot.db).db - db('counting', 'count', args) + store = storage(ctx.guild.id, self.bot.store).store + await store('counting', 'count', args) await ctx.send(f"count set to {args}") diff --git a/cogs/misc.py b/cogs/misc.py index c5635c0..7be1338 100644 --- a/cogs/misc.py +++ b/cogs/misc.py @@ -11,4 +11,8 @@ class Misc(commands.Cog): @bridge.bridge_command() async def version(self, ctx): - await ctx.send(self.bot.version) \ No newline at end of file + await ctx.send(self.bot.version) + + +def setup(bot): + bot.add_cog(Misc(bot)) \ No newline at end of file diff --git a/cogs/triggers.py b/cogs/triggers.py index 2317b78..1c776c8 100644 --- a/cogs/triggers.py +++ b/cogs/triggers.py @@ -9,11 +9,11 @@ class Triggers(commands.Cog): async def on_message(self, message): if message.author.bot: return - db = storage(message.guild.id, self.bot.db).db - if db('triggers', 'enabled'): - for trigger in db('triggers', 'triggers'): + store = storage(message.guild.id, self.bot.db).store + if await store('triggers', 'enabled') == "True": + for trigger in await store('triggers', 'triggers'): if trigger.lower() in message.content.lower(): - await message.reply(db('triggers', 'response')) + await message.reply(store('triggers', 'response')) def setup(bot): bot.add_cog(Triggers(bot)) \ No newline at end of file diff --git a/compose/compose-dev.yaml b/compose/compose-dev.yaml new file mode 100644 index 0000000..994d8e9 --- /dev/null +++ b/compose/compose-dev.yaml @@ -0,0 +1,39 @@ +services: + turdbot: + image: ionburger/turdbot + restart: always + container_name: turdbot + depends_on: + - mongodb + environment: + - BOT_TOKEN=${BOT_TOKEN} + - DB_HOST=mongodb + - DB_USERNAME=${DB_USERNAME} + - DB_PASSWORD=${DB_PASSWORD} + volumes: + - ../:/app + + flask: + image: ionburger/turdweb + restart: always + container_name: turdweb + depends_on: + - mongodb + environment: + - DB_HOST=mongodb + - DB_USERNAME=${DB_USERNAME} + - DB_PASSWORD=${DB_PASSWORD} + ports: + - "5005:5005" + + mongodb: + image: mongo + restart: always + container_name: mongodb + environment: + - MONGO_INITDB_ROOT_USERNAME=${DB_USERNAME} + - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} + ports: + - "27017:27017" + volumes: + - ${DB_LOCATION}:/data/db