FileIO to DataIO conversion (#410)

This commit is contained in:
Twentysix
2016-10-10 03:40:09 +02:00
committed by GitHub
parent 7dc597a272
commit 7a3c963009
8 changed files with 110 additions and 90 deletions

View File

@@ -1,17 +1,18 @@
import discord
from discord.ext import commands
from .utils.dataIO import fileIO
from .utils.dataIO import dataIO
from .utils import checks
from __main__ import user_allowed, send_cmd_help
from __main__ import user_allowed
import os
import re
class CustomCommands:
"""Custom commands."""
def __init__(self, bot):
self.bot = bot
self.c_commands = fileIO("data/customcom/commands.json", "load")
self.file_path = "data/customcom/commands.json"
self.c_commands = dataIO.load_json(self.file_path)
@commands.command(pass_context=True, no_pm=True)
@checks.mod_or_permissions(administrator=True)
@@ -32,7 +33,7 @@ class CustomCommands:
if command not in cmdlist:
cmdlist[command] = text
self.c_commands[server.id] = cmdlist
fileIO("data/customcom/commands.json", "save", self.c_commands)
dataIO.save_json(self.file_path, self.c_commands)
await self.bot.say("Custom command successfully added.")
else:
await self.bot.say("This command already exists. Use editcom to edit it.")
@@ -52,7 +53,7 @@ class CustomCommands:
if command in cmdlist:
cmdlist[command] = text
self.c_commands[server.id] = cmdlist
fileIO("data/customcom/commands.json", "save", self.c_commands)
dataIO.save_json(self.file_path, self.c_commands)
await self.bot.say("Custom command successfully edited.")
else:
await self.bot.say("That command doesn't exist. Use addcom [command] [text]")
@@ -73,7 +74,7 @@ class CustomCommands:
if command in cmdlist:
cmdlist.pop(command, None)
self.c_commands[server.id] = cmdlist
fileIO("data/customcom/commands.json", "save", self.c_commands)
dataIO.save_json(self.file_path, self.c_commands)
await self.bot.say("Custom command successfully deleted.")
else:
await self.bot.say("That command doesn't exist.")
@@ -172,9 +173,9 @@ def check_folders():
def check_files():
f = "data/customcom/commands.json"
if not fileIO(f, "check"):
if not dataIO.is_valid_json(f):
print("Creating empty commands.json...")
fileIO(f, "save", {})
dataIO.save_json(f, {})
def setup(bot):
check_folders()