Quotes can now be added to quote.json

This commit is contained in:
scummboy 2016-02-10 21:40:40 +00:00
parent f2e9c420e9
commit 89d443dde5

View File

@ -2,6 +2,7 @@ import discord
from discord.ext import commands
from .utils.dataIO import fileIO
from .utils import checks
from datetime import date
import os
class Quote:
@ -12,7 +13,7 @@ class Quote:
self.q_quote = fileIO("data/quote/quote.json", "load")
@commands.command(pass_context=True, no_pm=True)
async def addquote(self, ctx, quote : str, *text):
async def addquote(self, ctx : str, *text):
"""Adds a quote to the database
Example:
@ -27,25 +28,16 @@ class Quote:
if not server.id in self.q_quote:
self.q_quote[server.id] = {}
quotelist = self.q_quote[server.id]
if quote not in quotelist:
quotelist[quote] = text
print(quotelist[quote])
if text not in quotelist:
d = date.today()
quotelist[text] = d.strftime("%d/%m/%Y")
self.q_quote[server.id] = quotelist
print(self.q_quote)
fileIO("data/quote/quote.json", "save", self.q_quote)
await self.bot.say("`Quote added.`")
else:
await self.bot.say("`Quote already exists.`")
async def checkQ(self, message):
if message.author.id == self.bot.user.id or len(message.content) < 2 or message.channel.is_private:
return
msg = message.content
server = message.server
if msg[0] in self.bot.command_prefix and server.id in self.q_quote.keys():
quotelist = self.q_quote[server.id]
if msg[1:] in quotelist:
await self.bot.send_message(message.channel, quotelist[msg[1:]])
def check_folders():
if not os.path.exists("data/quote"):
@ -62,5 +54,4 @@ def setup(bot):
check_folders()
check_files()
n = Quote(bot)
bot.add_listener(n.checkQ, "on_message")
bot.add_cog(n)