Browse Source

more work on custom commands. Can add and actually output commands. Now just need to make the edit, delete, and list commands.

tags/v1.1.0
roxie 6 years ago
parent
commit
6333a080fc
3 changed files with 41 additions and 6 deletions
  1. +36
    -6
      cogs/customcommands.py
  2. +1
    -0
      config/cogs.py
  3. +4
    -0
      config/server_config.py

+ 36
- 6
cogs/customcommands.py View File

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

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

class CustomCommands():
def __init__(self, Bot):
@@ -9,26 +10,55 @@ class CustomCommands():
self.con = ServerConfig()
self.servers = self.con.servers

async def on_message(self, message):
msg = message.content.lower()
channel = message.channel
server = message.server.id
if message.author == self.bot.user:
return
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:
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:
return await self.bot.say('Missing Argument')

@custom.command(pass_context=True)
async def add(self, ctx, command, output, prefix_required = 0):
print(prefix_required)
async def add(self, ctx, command, output, prefix_required = "0"):
command = command.lower()
output = output.lower()
if 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):
pass
try:
self.servers[ctx.message.server.id]["custom_commands"]["1"]["command"].popout()
except KeyError:
print("It worked")

@custom.command(pass_context=True)
async def remove(self, ctx, *, command):
pass
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")


@custom.command(pass_context=True)
async def list(self, ctx, *, command):
pass
command = command.lower()

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

+ 1
- 0
config/cogs.py View File

@@ -1,5 +1,6 @@
cogs = [
"cogs.fun",
"cogs.customcommands",
"cogs.joinleave",
"cogs.nsfw",
"cogs.reddit",

+ 4
- 0
config/server_config.py View File

@@ -37,6 +37,10 @@ class ServerConfig():
},
"admin_role": {
"role": ""
},
"custom_commands":{
"0": {},
"1": {}
}
}
}

Loading…
Cancel
Save