Skip to content

Commit c684051

Browse files
committed
Add db, prefix cog and update set cog
1 parent b5e0935 commit c684051

File tree

7 files changed

+75
-3
lines changed

7 files changed

+75
-3
lines changed

cogs/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from util.checks import is_bot_owner

cogs/config/db.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from discord.ext import commands
2+
from . import is_bot_owner
3+
from dataminer import bot_requests
4+
5+
class Db_cmds(commands.Cog):
6+
def __init__(self, bot):
7+
self.bot = bot
8+
9+
@is_bot_owner()
10+
@commands.group(name="db")
11+
async def _db(self, ctx):
12+
return
13+
14+
@is_bot_owner()
15+
@commands.cooldown(1, 20.0, commands.BucketType.user)
16+
@_db.command(name="add_field", aliases=["addfield", "fieldadd", "field_add"])
17+
async def _db_addfield(self, ctx, *, field_name: str, type):
18+
"""CREATE A NEW FIELD IN THE DATABASE"""
19+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
20+
21+
types = {
22+
"list": [],
23+
"object": {},
24+
"string": "",
25+
"int": int
26+
}
27+
self.bot.db.update_one({"_id": str(ctx.guild.id)}, {"$set": {field_name: types[type]}})
28+
29+
30+
def setup(bot):
31+
bot.add_cog(Db_cmds(bot))

cogs/config/prefix.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from discord.ext import commands
2+
import discord
3+
from dataminer import bot_requests
4+
from CONFIG import DEFAULT_PREFIX
5+
6+
class Prefix(commands.Cog):
7+
def __init__(self, bot):
8+
self.bot = bot
9+
10+
def prefix(self, server_id: str):
11+
pr_list = self.bot.db.find({"_id": server_id})
12+
for pr in pr_list:
13+
prefix = pr["prefix"]
14+
15+
return prefix, DEFAULT_PREFIX, f"<@{self.bot.user.id}>"
16+
17+
@commands.cooldown(1, 5.0, commands.BucketType.user)
18+
@commands.command(name="prefix")
19+
async def _prefix(self, ctx):
20+
"""SHOWS THE SERVER PREFIX """
21+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
22+
23+
embed = discord.Embed(title="Every prefix you can use on this server:", description=f", \n".join(self.prefix(str(ctx.guild.id))))
24+
return await ctx.send(embed=embed)
25+
26+
def setup(bot):
27+
bot.add_cog(Prefix(bot))

cogs/config/set.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from . import is_bot_owner
33
import discord
44
import asyncio
5+
from dataminer import bot_requests
56

67
class Set(commands.Cog):
78
def __init__(self, bot):
@@ -12,13 +13,20 @@ def __init__(self, bot):
1213
@commands.group(name="set")
1314
async def _set(self, ctx):
1415
"""RETURN ALL AVAILABLE SET FUNCTIONS"""
15-
return
16+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
17+
18+
embed = discord.Embed(title="`Set` commands")
19+
embed.add_field(name="`set game <NAME>`", value="Set the game/status of the bot", inline=False)
20+
embed.add_field(name="`set prefix <PREFIX>`", value="Set the server prefix", inline=False)
21+
return await ctx.send(embed=embed)
1622

1723
@is_bot_owner()
1824
@commands.cooldown(1, 10.0, commands.BucketType.user)
1925
@_set.command(name="game")
2026
async def _set_game(self, ctx, *, game_name: str):
2127
"""SET BOT GAME"""
28+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
29+
2230
await ctx.send(f"React with 👌 to change the game to `{game_name}`!")
2331

2432
def check(reaction, user):
@@ -38,6 +46,8 @@ def check(reaction, user):
3846
@_set.command(name="prefix")
3947
async def _set_prefix(self, ctx, *, prefix: str):
4048
"""SET A SERVER PREFIX"""
49+
bot_requests(ctx.message, str(ctx.command), self.bot.db)
50+
4151
self.bot.db.update({"_id": str(ctx.guild.id)}, {"$set": {"prefix": prefix}})
4252

4353
await ctx.send("React with 👌 to change the prefix!")

core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from core.bot import run, Bot
2-
from core.database import DbClient, Database
2+
from core.database import DbClient, Database
3+
from CONFIG import DEFAULT_PREFIX

core/cogs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
"util.error",
1010
"cogs.plot",
1111
"cogs.config.set",
12-
"cogs.config.db"]
12+
"cogs.config.db",
13+
"cogs.config.prefix"]

util/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from CONFIG import OWNER_ID

0 commit comments

Comments
 (0)