3.2
This commit is contained in:
parent
82531f9645
commit
ad72aeb8ce
@ -10,7 +10,7 @@ services:
|
||||
- DB_HOST=mongodb
|
||||
- DB_USERNAME=${DB_USERNAME}
|
||||
- DB_PASSWORD=${DB_PASSWORD}
|
||||
|
||||
|
||||
mongodb:
|
||||
image: mongo
|
||||
restart: always
|
||||
|
||||
@ -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)
|
||||
self.serverdb.update_one({"module": module}, {"$set": {key: value}}, upsert=True)
|
||||
return r
|
||||
@ -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"])
|
||||
@ -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')}")
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user