-
Notifications
You must be signed in to change notification settings - Fork 52
/
config.py
77 lines (68 loc) · 3.9 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import logging
from discord.ext import commands
class Config(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
@commands.has_permissions(manage_guild=True)
async def prefix(self, ctx, *, pre):
"""Set a custom prefix for the server."""
server = ctx.message.guild
if pre.endswith('\w'):
pre = pre[:-2]+' '
if len(pre.strip) > 0:
msg = f'The server prefix has been set to `{pre}` Use `{pre}prefix <prefix>` to change it again.'
else:
await ctx.send('Invalid prefix.')
return
else:
msg = f'The server prefix has been set to `{pre}` Use `{pre}prefix <prefix>` to change it again. ' \
f'If you would like to add a trailing whitespace to the prefix, use `{pre}prefix {pre}\w`.'
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'prefix': str(pre)}}, upsert=True)
self.bot.pre[str(server.id)] = str(pre)
await ctx.send(msg)
@commands.command()
@commands.has_permissions(manage_guild=True)
async def adminrole(self, ctx, *, role=None):
"""Set or show the Admin Role. Members with this role can create polls and manage ALL polls. Parameter: <role> (optional)"""
server = ctx.message.guild
if not role:
result = await self.bot.db.config.find_one({'_id': str(server.id)})
if result and result.get('admin_role'):
await ctx.send(f'The admin role restricts which users are able to create and manage ALL polls on this server. \n'
f'The current admin role is `{result.get("admin_role")}`. '
f'To change it type `{result.get("prefix")}adminrole <role name>`')
else:
await ctx.send(f'The admin role restricts which users are able to create and manage ALL polls on this server. \n'
f'No admin role set. '
f'To set one type `{result.get("prefix")}adminrole <role name>`')
elif role in [r.name for r in server.roles]:
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'admin_role': str(role)}}, upsert=True)
await ctx.send(f'Server role `{role}` can now manage all polls.')
else:
await ctx.send(f'Server role `{role}` not found.')
@commands.command()
@commands.has_permissions(manage_guild=True)
async def userrole(self, ctx, *, role=None):
"""Set or show the User Role. Members with this role can create polls and manage their own polls.
Parameter: <role> (optional)"""
server = ctx.message.guild
if not role:
result = await self.bot.db.config.find_one({'_id': str(server.id)})
if result and result.get('user_role'):
await ctx.send(f'The user role restricts which users are able to create and manage their own polls. \n'
f'The current user role is `{result.get("user_role")}`. '
f'To change it type `{result.get("prefix")}userrole <role name>`')
else:
await ctx.send(f'The user role restricts which users are able to create and manage their own polls. \n'
f'No user role set. '
f'To set one type `{result.get("prefix")}userrole <role name>`')
elif role in [r.name for r in server.roles]:
await self.bot.db.config.update_one({'_id': str(server.id)}, {'$set': {'user_role': str(role)}}, upsert=True)
await ctx.send(f'Server role `{role}` can now create and manage their own polls.')
else:
await ctx.send(f'Server role `{role}` not found.')
def setup(bot):
global logger
logger = logging.getLogger('discord')
bot.add_cog(Config(bot))