This commit is contained in:
Ian Burgess 2024-06-19 22:22:21 -06:00
parent 229669d557
commit 0823552a2d
6 changed files with 63 additions and 18 deletions

View File

@ -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:

2
bot.py
View File

@ -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"])

View File

@ -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}")

View File

@ -11,4 +11,8 @@ class Misc(commands.Cog):
@bridge.bridge_command()
async def version(self, ctx):
await ctx.send(self.bot.version)
await ctx.send(self.bot.version)
def setup(bot):
bot.add_cog(Misc(bot))

View File

@ -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))

39
compose/compose-dev.yaml Normal file
View File

@ -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