Browse Source

custom commands mostly done wtf

tags/v1.1.0
roxie 6 years ago
parent
commit
ad635a5bd1
2 changed files with 60 additions and 17 deletions
  1. +59
    -16
      cogs/customcommands.py
  2. +1
    -1
      config/servers.json

+ 59
- 16
cogs/customcommands.py View File

@@ -1,6 +1,7 @@
from discord.ext.commands import bot
import discord
from discord.ext.commands import group
from config.server_config import ServerConfig
import load_config

# TODO: Sort out admin commands, mod commands, the settings before ever pushing this to general use. It needs to be a mod only thing.

@@ -19,11 +20,10 @@ class CustomCommands():
if msg.startswith(self.bot.command_prefix):
if msg.split(self.bot.command_prefix)[1] in self.servers[server]["custom_commands"]["1"]:
return await self.bot.send_message(channel, self.servers[server]["custom_commands"]["1"][msg.split(self.bot.command_prefix)[1]])
elif len(msg.split(" ")) < 3:
elif len(msg.split(" ")) < 2:
if msg.split(" ")[0] in self.servers[server]["custom_commands"]["0"]:
return await self.bot.send_message(channel, self.servers[server]["custom_commands"]["0"][msg.split(" ")[0]])


@group(pass_context=True, aliases=["cc"])
async def custom(self, ctx):
if ctx.invoked_subcommand is None:
@@ -33,32 +33,75 @@ class CustomCommands():
async def add(self, ctx, command, output, prefix_required = "0"):
command = command.lower()
output = output.lower()
if prefix_required != "1" and prefix_required != "0":
zero = self.servers[ctx.message.server.id]["custom_commands"]["0"]
one = self.servers[ctx.message.server.id]["custom_commands"]["1"]

if ctx.message.mentions:
return await self.bot.say("Custom Commands cannot mention people.")
elif len(output) > 1999: # This probably wont happen atm since the command itself would make the whole message over len 2000 which would be impossible to send. But this is here incase we need to adjust this number.
return await self.bot.say("The output is too long")
elif command in self.bot.commands and prefix_required == "1":
return await self.bot.say("This is already the name of a built in command.")
elif command in zero or command in one:
return await self.bot.say("Custom Command already exists.")
elif prefix_required != "1" and prefix_required != "0":
return await self.bot.say("No prefix setting set.")

self.servers[ctx.message.server.id]["custom_commands"][prefix_required][command] = output
self.con.update_config(self.servers)
return await self.bot.say("{} has been added with the output: '{}'".format(command, output))

@custom.command(pass_context=True)
async def edit(self, ctx, *, command):
try:
self.servers[ctx.message.server.id]["custom_commands"]["1"]["command"].popout()
except KeyError:
print("It worked")
async def edit(self, ctx, command, edit):
zero = self.servers[ctx.message.server.id]["custom_commands"]["0"]
one = self.servers[ctx.message.server.id]["custom_commands"]["1"]

if ctx.message.mentions:
return await self.bot.say("Custom Commands cannot mention people.")

if command in zero:
self.servers[ctx.message.server.id]["custom_commands"]["0"][command] = edit
self.con.update_config(self.servers)
return await self.bot.say("Edit made. {} now outputs {}".format(command, edit))
elif command in one:
self.servers[ctx.message.server.id]["custom_commands"]["1"][command] = edit
self.con.update_config(self.servers)
return await self.bot.say("Edit made. {} now outputs {}".format(command, edit))
else:
return await self.bot.say("That Custom Command doesn't exist.")

@custom.command(pass_context=True)
async def remove(self, ctx, command):
command = command.lower()
try:
if command in self.servers[ctx.message.server.id]["custom_commands"]["1"]:
self.servers[ctx.message.server.id]["custom_commands"]["1"][command].popout()
except:
print("It worked")
if command in self.servers[ctx.message.server.id]["custom_commands"]["1"]:
self.servers[ctx.message.server.id]["custom_commands"]["1"].pop(command)
self.con.update_config(self.servers)
return await self.bot.say("Removed {} custom command".format(command))
elif command in self.servers[ctx.message.server.id]["custom_commands"]["0"]:
self.servers[ctx.message.server.id]["custom_commands"]["0"].pop(command)
self.con.update_config(self.servers)
return await self.bot.say("Removed {} custom command".format(command))
else:
return await self.bot.say("Custom Command doesn't exist.")


@custom.command(pass_context=True)
async def list(self, ctx, *, command):
command = command.lower()
async def list(self, ctx):
l = self.servers[ctx.message.server.id]["custom_commands"]
listzero = ""
listone = ""
for command in l["0"]:
listzero = listzero + "- " + command + "\n"
for command in l["1"]:
listone = listone + "- " + command + "\n"
if not listone:
listone = "There are no commands setup.\n"
if not listzero:
listzero = "There are no commands setup.\n"
em = discord.Embed(title="Here is the list of Custom Commands", color=load_config.embedcolour)
em.add_field(name="Commands that require Prefix:", value=listone, inline=False)
em.add_field(name="Commands that don't:", value=listzero, inline=False)
return await self.bot.say(embed=em)

def setup(Bot):
Bot.add_cog(CustomCommands(Bot))

+ 1
- 1
config/servers.json View File

@@ -1 +1 @@
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 1}, "admin_role": {"role": ""}}}
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0}, "admin_role": {"role": ""}, "custom_commands": {"0": {"test": "\"testedit\"", "hello": "<:tingles:346838411639914506>", "benis": "\ud83c\udd71enis", "sophie": "<@136619052994002944>", "myra": "<@342213251372941312>", "roxieee": "<@!142735312626515979>", "customs": "\"\ud83d\udec3\"", "zzz": "\ud83d\udca4", "lewd!": "\ud83d\udea8 lewd! \ud83d\udea8"}, "1": {}}}}

Loading…
Cancel
Save