From 82531f9645209efac1ac1e5c77948b9099bd642e Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 12 Mar 2024 13:14:01 -0600 Subject: [PATCH] 3.0 --- .env.example | 3 +++ compose.yaml | 22 ++++++++++++++++++++++ compose.yaml.prod | 21 +++++++++++++++++++++ py/Dockerfile | 6 ++++++ py/bin/imagematcher.py | 0 py/bot.py | 35 ++++++++++++++++++----------------- py/cogs/counting.py | 34 +++++++++++++++++++++++++++++++++- py/cogs/repost.py | 23 ----------------------- py/config/bot.conf.example | 0 py/requirements.txt | 3 +++ 10 files changed, 106 insertions(+), 41 deletions(-) create mode 100644 .env.example create mode 100644 compose.yaml create mode 100644 compose.yaml.prod create mode 100644 py/Dockerfile delete mode 100644 py/bin/imagematcher.py delete mode 100644 py/cogs/repost.py delete mode 100644 py/config/bot.conf.example create mode 100644 py/requirements.txt diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1b819cd --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +BOT_TOKEN=bot_token +DB_USERNAME=databaseuser +DB_PASSWORD=databasepass diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..d5fc25a --- /dev/null +++ b/compose.yaml @@ -0,0 +1,22 @@ +services: + turdbot: + image: "ionburger/turdbot:latest" + restart: always + container_name: turdbot + depends_on: + - mongodb + environment: + - BOT_TOKEN=${BOT_TOKEN} + - DB_HOST=mongodb + - DB_USERNAME=${DB_USERNAME} + - DB_PASSWORD=${DB_PASSWORD} + + mongodb: + image: mongo + restart: always + container_name: mongodb + environment: + - MONGO_INITDB_ROOT_USERNAME=${DB_USERNAME} + - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} + ports: + - "27017:27017" diff --git a/compose.yaml.prod b/compose.yaml.prod new file mode 100644 index 0000000..bb99adb --- /dev/null +++ b/compose.yaml.prod @@ -0,0 +1,21 @@ +services: + turdbot: + image: "ionburger/turdbot:latest" + restart: always + container_name: turdbot + depends_on: + - mongodb + environment: + - BOT_TOKEN=${BOT_TOKEN} + - DB_HOST=mongodb + - DB_USERNAME=${DB_USERNAME} + - DB_PASSWORD=${DB_PASSWORD} + + mongodb: + image: mongo + restart: always + container_name: mongodb + environment: + - MONGO_INITDB_ROOT_USERNAME=${DB_USERNAME} + - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} + diff --git a/py/Dockerfile b/py/Dockerfile new file mode 100644 index 0000000..0aeb8ec --- /dev/null +++ b/py/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.12-slim +RUN mkdir -p /app +COPY . /app +WORKDIR /app +RUN pip install -r requirements.txt +ENTRYPOINT ["python", "-u", "bot.py"] \ No newline at end of file diff --git a/py/bin/imagematcher.py b/py/bin/imagematcher.py deleted file mode 100644 index e69de29..0000000 diff --git a/py/bot.py b/py/bot.py index 10adc30..2cbc03f 100644 --- a/py/bot.py +++ b/py/bot.py @@ -1,15 +1,11 @@ -import configparser +from os import environ as env import discord from discord.ext import bridge -import discord import logging from pymongo import MongoClient +from bin.storage import storage -logging.basicConfig(level=logging.WARNING) - -config = configparser.ConfigParser() -config.read("config/bot.conf") - +logging.basicConfig(filename="turdbot.log",level=logging.INFO) bot = bridge.Bot( help_command=None, @@ -20,17 +16,22 @@ bot = bridge.Bot( name="you") ) +bot.load_extension("cogs.reply") +bot.load_extension("cogs.counting") + +uri = f"mongodb://{env['DB_USERNAME']}:{env['DB_PASSWORD']}@{env['DB_HOST']}/?authSource=admin" +bot.db = MongoClient(uri)["turdbot"] + @bot.event async def on_ready(): - print(f"Logged in as {bot.user} (ID: {bot.user.id})") - - bot.load_extension("cogs.reply") - bot.load_extension("cogs.repost") - # bot.load_extension("cogs.counting") - # bot.load_extension("cogs.test") - - - bot.db = MongoClient(config["DATABASE"]["uri"])["main"] + 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() -bot.run(config["MAIN"]["token"]) \ No newline at end of file +bot.run(env["BOT_TOKEN"]) \ No newline at end of file diff --git a/py/cogs/counting.py b/py/cogs/counting.py index 2dbd456..e0066e1 100644 --- a/py/cogs/counting.py +++ b/py/cogs/counting.py @@ -1,6 +1,38 @@ -from discord.ext import bridge +from discord.ext import bridge, commands +from bin.storage import storage +class Counting(commands.Cog): + def __init__(self, bot): + self.bot = bot + @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]) + + if message.author.bot or message.channel.id != db('counting', 'channel') or not message.content.isdigit(): + return + + elif message.author.id == db('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 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("counting channel set") + + def setup(bot): diff --git a/py/cogs/repost.py b/py/cogs/repost.py deleted file mode 100644 index fa666ee..0000000 --- a/py/cogs/repost.py +++ /dev/null @@ -1,23 +0,0 @@ -from discord.ext import bridge, commands -import discord -from bin.storage import storage - -#import opencv -#from bin.imagematcher import imagematcher - -class Repost(commands.Cog): - def __init__(self, bot): - self.bot = bot - - @bridge.bridge_command() - async def repost(self, ctx): - st = storage("test", self.bot.db) - #referenceimgurl = ctx.channel.fetch_message(ctx.message.reference.message_id).attachments[0].url - msgs = await ctx.channel.history(limit=100).flatten() - l = {} - for msg in msgs: - for attachment in msg.attachments: - l[msg.id] = attachment.url - st.db("test", "test", l) -def setup(bot): - bot.add_cog(Repost(bot)) \ No newline at end of file diff --git a/py/config/bot.conf.example b/py/config/bot.conf.example deleted file mode 100644 index e69de29..0000000 diff --git a/py/requirements.txt b/py/requirements.txt new file mode 100644 index 0000000..c59fc63 --- /dev/null +++ b/py/requirements.txt @@ -0,0 +1,3 @@ +py-cord[audio] +pymongo +PyNaCl \ No newline at end of file