mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[CC] [p]cc list: Sends to channel or DM based on message length
This commit is contained in:
parent
7a38da9152
commit
07c07760c9
@ -1,7 +1,7 @@
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from .utils.dataIO import dataIO
|
from .utils.dataIO import dataIO
|
||||||
from .utils import checks
|
from .utils import checks
|
||||||
from __main__ import user_allowed
|
from .utils.chat_formatting import pagify, box
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -102,29 +102,22 @@ class CustomCommands:
|
|||||||
async def cc_list(self, ctx):
|
async def cc_list(self, ctx):
|
||||||
"""Shows custom commands list"""
|
"""Shows custom commands list"""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
if server.id in self.c_commands:
|
commands = self.c_commands.get(server.id, {})
|
||||||
cmdlist = self.c_commands[server.id]
|
|
||||||
if cmdlist:
|
if not commands:
|
||||||
i = 0
|
|
||||||
msg = ["```Custom commands:\n"]
|
|
||||||
for cmd in sorted([cmd for cmd in cmdlist]):
|
|
||||||
if len(msg[i]) + len(ctx.prefix) + len(cmd) + 5 > 2000:
|
|
||||||
msg[i] += "```"
|
|
||||||
i += 1
|
|
||||||
msg.append("``` {}{}\n".format(ctx.prefix, cmd))
|
|
||||||
else:
|
|
||||||
msg[i] += " {}{}\n".format(ctx.prefix, cmd)
|
|
||||||
msg[i] += "```"
|
|
||||||
for cmds in msg:
|
|
||||||
await self.bot.whisper(cmds)
|
|
||||||
else:
|
|
||||||
await self.bot.say("There are no custom commands in this server."
|
|
||||||
" Use `{}customcom add` to start adding some."
|
|
||||||
"".format(ctx.prefix))
|
|
||||||
else:
|
|
||||||
await self.bot.say("There are no custom commands in this server."
|
await self.bot.say("There are no custom commands in this server."
|
||||||
" Use `{}customcom add` to start adding some."
|
" Use `{}customcom add` to start adding some."
|
||||||
"".format(ctx.prefix))
|
"".format(ctx.prefix))
|
||||||
|
return
|
||||||
|
|
||||||
|
commands = ", ".join([ctx.prefix + c for c in sorted(commands)])
|
||||||
|
commands = "Custom commands:\n\n" + commands
|
||||||
|
|
||||||
|
if len(commands) < 1500:
|
||||||
|
await self.bot.say(box(commands))
|
||||||
|
else:
|
||||||
|
for page in pagify(commands, delims=[" ", "\n"]):
|
||||||
|
await self.bot.whisper(box(page))
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
if len(message.content) < 2 or message.channel.is_private:
|
if len(message.content) < 2 or message.channel.is_private:
|
||||||
@ -136,7 +129,7 @@ class CustomCommands:
|
|||||||
if not prefix:
|
if not prefix:
|
||||||
return
|
return
|
||||||
|
|
||||||
if server.id in self.c_commands and user_allowed(message):
|
if server.id in self.c_commands and self.bot.user_allowed(message):
|
||||||
cmdlist = self.c_commands[server.id]
|
cmdlist = self.c_commands[server.id]
|
||||||
cmd = message.content[len(prefix):]
|
cmd = message.content[len(prefix):]
|
||||||
if cmd in cmdlist:
|
if cmd in cmdlist:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user