mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 19:58:54 -05:00
Quotes can now be added to quote.json
This commit is contained in:
parent
f2e9c420e9
commit
89d443dde5
@ -2,6 +2,7 @@ import discord
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from .utils.dataIO import fileIO
|
from .utils.dataIO import fileIO
|
||||||
from .utils import checks
|
from .utils import checks
|
||||||
|
from datetime import date
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class Quote:
|
class Quote:
|
||||||
@ -12,7 +13,7 @@ class Quote:
|
|||||||
self.q_quote = fileIO("data/quote/quote.json", "load")
|
self.q_quote = fileIO("data/quote/quote.json", "load")
|
||||||
|
|
||||||
@commands.command(pass_context=True, no_pm=True)
|
@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
|
"""Adds a quote to the database
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@ -27,25 +28,16 @@ class Quote:
|
|||||||
if not server.id in self.q_quote:
|
if not server.id in self.q_quote:
|
||||||
self.q_quote[server.id] = {}
|
self.q_quote[server.id] = {}
|
||||||
quotelist = self.q_quote[server.id]
|
quotelist = self.q_quote[server.id]
|
||||||
if quote not in quotelist:
|
if text not in quotelist:
|
||||||
quotelist[quote] = text
|
d = date.today()
|
||||||
print(quotelist[quote])
|
quotelist[text] = d.strftime("%d/%m/%Y")
|
||||||
self.q_quote[server.id] = quotelist
|
self.q_quote[server.id] = quotelist
|
||||||
print(self.q_quote)
|
|
||||||
fileIO("data/quote/quote.json", "save", self.q_quote)
|
fileIO("data/quote/quote.json", "save", self.q_quote)
|
||||||
await self.bot.say("`Quote added.`")
|
await self.bot.say("`Quote added.`")
|
||||||
else:
|
else:
|
||||||
await self.bot.say("`Quote already exists.`")
|
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():
|
def check_folders():
|
||||||
if not os.path.exists("data/quote"):
|
if not os.path.exists("data/quote"):
|
||||||
@ -62,5 +54,4 @@ def setup(bot):
|
|||||||
check_folders()
|
check_folders()
|
||||||
check_files()
|
check_files()
|
||||||
n = Quote(bot)
|
n = Quote(bot)
|
||||||
bot.add_listener(n.checkQ, "on_message")
|
|
||||||
bot.add_cog(n)
|
bot.add_cog(n)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user