mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
Custom commands now work with multichar prefixes
This commit is contained in:
parent
8ef6853f28
commit
e964deaf1a
@ -2,6 +2,7 @@ import discord
|
||||
from discord.ext import commands
|
||||
from .utils.dataIO import fileIO
|
||||
from .utils import checks
|
||||
from __main__ import user_allowed
|
||||
import os
|
||||
|
||||
class CustomCommands:
|
||||
@ -86,12 +87,25 @@ class CustomCommands:
|
||||
async def checkCC(self, message):
|
||||
if message.author.id == self.bot.user.id or len(message.content) < 2 or message.channel.is_private:
|
||||
return
|
||||
|
||||
if not user_allowed(message):
|
||||
return
|
||||
|
||||
msg = message.content
|
||||
server = message.server
|
||||
if msg[0] in self.bot.command_prefix and server.id in self.c_commands.keys():
|
||||
prefix = self.get_prefix(msg)
|
||||
|
||||
if prefix and server.id in self.c_commands.keys():
|
||||
cmdlist = self.c_commands[server.id]
|
||||
if msg[1:] in cmdlist:
|
||||
await self.bot.send_message(message.channel, cmdlist[msg[1:]])
|
||||
cmd = msg[len(prefix):]
|
||||
if cmd in cmdlist.keys():
|
||||
await self.bot.send_message(message.channel, cmdlist[cmd])
|
||||
|
||||
def get_prefix(self, msg):
|
||||
for p in self.bot.command_prefix:
|
||||
if msg.startswith(p):
|
||||
return p
|
||||
return False
|
||||
|
||||
def check_folders():
|
||||
if not os.path.exists("data/customcom"):
|
||||
|
||||
64
red.py
64
red.py
@ -44,36 +44,8 @@ async def on_command(command, ctx):
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
mod = bot.get_cog('Mod')
|
||||
author = message.author
|
||||
|
||||
if mod is not None:
|
||||
if checks.settings["OWNER"] == author.id:
|
||||
await bot.process_commands(message)
|
||||
return
|
||||
if not message.channel.is_private:
|
||||
if discord.utils.get(author.roles, name=checks.settings["ADMIN_ROLE"]) is not None:
|
||||
await bot.process_commands(message)
|
||||
return
|
||||
if discord.utils.get(author.roles, name=checks.settings["MOD_ROLE"]) is not None:
|
||||
await bot.process_commands(message)
|
||||
return
|
||||
|
||||
if author.id in mod.blacklist_list:
|
||||
return
|
||||
|
||||
if mod.whitelist_list:
|
||||
if author.id not in mod.whitelist_list:
|
||||
return
|
||||
|
||||
if not message.channel.is_private:
|
||||
if message.server.id in mod.ignore_list["SERVERS"]:
|
||||
return
|
||||
|
||||
if message.channel.id in mod.ignore_list["CHANNELS"]:
|
||||
return
|
||||
|
||||
await bot.process_commands(message)
|
||||
if user_allowed(message):
|
||||
await bot.process_commands(message)
|
||||
|
||||
@bot.command()
|
||||
@checks.is_owner()
|
||||
@ -212,6 +184,38 @@ async def _uptime():
|
||||
up = str(datetime.timedelta(seconds=up))
|
||||
await bot.say("`Uptime: {}`".format(up))
|
||||
|
||||
def user_allowed(message):
|
||||
|
||||
author = message.author
|
||||
|
||||
mod = bot.get_cog('Mod')
|
||||
|
||||
if mod is not None:
|
||||
if checks.settings["OWNER"] == author.id:
|
||||
return True
|
||||
if not message.channel.is_private:
|
||||
if discord.utils.get(author.roles, name=checks.settings["ADMIN_ROLE"]) is not None:
|
||||
return True
|
||||
if discord.utils.get(author.roles, name=checks.settings["MOD_ROLE"]) is not None:
|
||||
return True
|
||||
|
||||
if author.id in mod.blacklist_list:
|
||||
return False
|
||||
|
||||
if mod.whitelist_list:
|
||||
if author.id not in mod.whitelist_list:
|
||||
return False
|
||||
|
||||
if not message.channel.is_private:
|
||||
if message.server.id in mod.ignore_list["SERVERS"]:
|
||||
return False
|
||||
|
||||
if message.channel.id in mod.ignore_list["CHANNELS"]:
|
||||
return False
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
def wait_for_answer(author):
|
||||
global lock
|
||||
print(author.name + " requested to be set as owner. If this is you, type 'yes'. Otherwise press enter.")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user