-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
116 lines (90 loc) · 4.35 KB
/
bot.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import discord
from discord.ext import commands
from util.functions import randomDiscordColor, isMod # pylint: disable=no-name-in-module
import models
from util.publicCommands import publicCommand, publicCommands # pylint: disable=no-name-in-module
class Bot(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
@commands.is_owner()
async def config(self, ctx: commands.Context):
"""
Configure the bot.
Asks the required IDs for channels and stores them in database
"""
def pred(m):
return m.author == ctx.author and m.channel == ctx.channel
await ctx.send('What channel do you want to use for self assignable roles? Please enter the channel ID')
rolesCnlId = await self.bot.wait_for('message', check=pred)
await ctx.send('What are the role IDs for mod roles? Please the role IDs with commas')
modIdsMsg = await self.bot.wait_for('message', check=pred)
modIds = [int(str(id).strip()) for id in str(modIdsMsg.content).split(',')]
await ctx.send('What channel do you want to use for welcome message? Please enter the channel ID')
welcomeCnlId = await self.bot.wait_for('message', check=pred)
await ctx.send('What is the role ID for muted role')
mutedRoleId = await self.bot.wait_for('message', check=pred)
await ctx.send('What is the role ID for member role?')
memberRoleId = await self.bot.wait_for('message', check=pred)
botConfig = models.BotConfig.BotConfig(
serverId = ctx.guild.id,
rolesChannelId = rolesCnlId.content,
modIds = modIds,
welcomeChannel = welcomeCnlId.content,
memberRoleId = memberRoleId.content,
mutedRoleId = mutedRoleId.content,
)
botConfig.save()
await ctx.send(f'Great! The channel for self assignable roles is {botConfig.rolesChannelId}\nMod IDs are {botConfig.modIds}\nWelcome channel is {botConfig.welcomeChannel}\nMuted Role Id is {botConfig.mutedRoleId}\nMember Role ID is {botConfig.memberRoleId}')
@commands.command()
@commands.is_owner()
async def reload(self, ctx: commands.Context, module: str):
"""
Reloads a cog
"""
if module == 'bot':
self.bot.reload_extension('bot')
else:
self.bot.reload_extension(f'cogs.{module}')
await ctx.send("🔄")
@publicCommand
@commands.command()
async def help(self, ctx: commands.Context, command: str = None):
"""
Displays help message
"""
embed = discord.Embed(title='**You wanted help? Help is provided**', color = randomDiscordColor())
embed.set_footer(text=f'Do {self.bot.command_prefix}help commndName to get help for a specific command')
if command is None:
print(publicCommands)
for name, cog in self.bot.cogs.items():
out = ''
cmds = [x for x in cog.get_commands() if x.name in publicCommands or (await self.bot.is_owner(ctx.author)) or (isMod(ctx) and 'is_owner' not in str(x.checks))]
for cmd in cmds:
helpStr = str(cmd.help).split('\n')[0]
out += f"**{cmd.name}**:\t{helpStr}\n"
if out:
embed.add_field(name=f'**{name}**', value=out, inline=False)
else:
cmd = self.bot.get_command(command)
try:
canRun = await cmd.can_run(ctx)
except commands.errors.CommandError:
canRun = False
print(canRun)
if cmd is None:
await ctx.send(f"Command {command} doesn't exist")
return
elif not canRun and not await self.bot.is_owner(ctx.author):
await ctx.send(f"You can't run {command} command")
return
embed.add_field(name = f'{cmd.name}', value = cmd.help, inline=False)
cmdAliases = cmd.aliases
if (cmdAliases):
aliases = ''
for i in range(0, len(cmdAliases)):
aliases += f'{i + 1}. {cmdAliases[i]}\n'
embed.add_field(name='Aliases:', value=aliases, inline=False)
await ctx.send(embed=embed)
def setup(bot: commands.Bot):
bot.add_cog(Bot(bot))