mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
The missing things
This commit is contained in:
parent
060b3a1296
commit
f2e9c420e9
66
cogs/quote.py
Normal file
66
cogs/quote.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from .utils.dataIO import fileIO
|
||||||
|
from .utils import checks
|
||||||
|
import os
|
||||||
|
|
||||||
|
class Quote:
|
||||||
|
"""Quotes"""
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
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):
|
||||||
|
"""Adds a quote to the database
|
||||||
|
|
||||||
|
Example:
|
||||||
|
!addquote Enter quote text here
|
||||||
|
"""
|
||||||
|
if text == ():
|
||||||
|
await self.bot.say("addquote [quote text]")
|
||||||
|
return
|
||||||
|
server = ctx.message.server
|
||||||
|
channel = ctx.message.channel
|
||||||
|
text = " ".join(text)
|
||||||
|
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])
|
||||||
|
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"):
|
||||||
|
print("Creating data/quote folder...")
|
||||||
|
os.makedirs("data/quote")
|
||||||
|
|
||||||
|
def check_files():
|
||||||
|
f = "data/quote/quote.json"
|
||||||
|
if not fileIO(f, "check"):
|
||||||
|
print("Creating empty quote.json...")
|
||||||
|
fileIO(f, "save", {})
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
check_folders()
|
||||||
|
check_files()
|
||||||
|
n = Quote(bot)
|
||||||
|
bot.add_listener(n.checkQ, "on_message")
|
||||||
|
bot.add_cog(n)
|
||||||
94
image.something
Normal file
94
image.something
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from random import randint
|
||||||
|
from imgurpython import ImgurClient
|
||||||
|
import aiohttp
|
||||||
|
import random
|
||||||
|
|
||||||
|
class Image:
|
||||||
|
"""Image related commands."""
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
#Reserved for further ... stuff
|
||||||
|
|
||||||
|
"""Commands section"""
|
||||||
|
|
||||||
|
@commands.command(no_pm=True)
|
||||||
|
async def imgur(self, *text):
|
||||||
|
"""Retrieves a random imgur picture.
|
||||||
|
imgur search [keyword] - retrieves first hit of search query.
|
||||||
|
imgur [subreddit section] [top or new] - retrieves top 3 hottest or latest pictures of today for given a subreddit section, e.g. 'funny'."""
|
||||||
|
imgurclient = ImgurClient("1fd3ef04daf8cab", "f963e574e8e3c17993c933af4f0522e1dc01e230")
|
||||||
|
if text == ():
|
||||||
|
rand = randint(0, 59) #60 results per generated page
|
||||||
|
items = imgurclient.gallery_random(page=0)
|
||||||
|
await self.bot.say(items[rand].link)
|
||||||
|
elif text[0] == "search":
|
||||||
|
items = imgurclient.gallery_search(" ".join(text[1:len(text)]), advanced=None, sort='time', window='all', page=0)
|
||||||
|
if len(items) < 1:
|
||||||
|
await self.bot.say("Your search terms gave no results.")
|
||||||
|
else:
|
||||||
|
await self.bot.say(items[0].link)
|
||||||
|
elif text[0] != ():
|
||||||
|
if text[1] == "top":
|
||||||
|
imgSort = "top"
|
||||||
|
elif text[1] == "new":
|
||||||
|
imgSort = "time"
|
||||||
|
else:
|
||||||
|
await self.bot.say("Only top or new is a valid subcommand.")
|
||||||
|
return
|
||||||
|
items = imgurclient.subreddit_gallery(text[0], sort=imgSort, window='day', page=0)
|
||||||
|
if (len(items) < 3):
|
||||||
|
await self.bot.say("This subreddit section does not exist, try 'funny'")
|
||||||
|
else:
|
||||||
|
await self.bot.say("{} {} {}".format(items[0].link, items[1].link, items[2].link))
|
||||||
|
|
||||||
|
@commands.command(no_pm=True)
|
||||||
|
async def gif(self, *text):
|
||||||
|
""" gif [keyword] - retrieves first search result from giphy """
|
||||||
|
if len(text) > 0:
|
||||||
|
if len(text[0]) > 1 and len(text[0]) < 20:
|
||||||
|
try:
|
||||||
|
msg = "+".join(text)
|
||||||
|
search = "http://api.giphy.com/v1/gifs/search?q=" + msg + "&api_key=dc6zaTOxFJmzC"
|
||||||
|
async with aiohttp.get(search) as r:
|
||||||
|
result = await r.json()
|
||||||
|
if result["data"] != []:
|
||||||
|
url = result["data"][0]["url"]
|
||||||
|
await self.bot.say(url)
|
||||||
|
else:
|
||||||
|
await self.bot.say("Your search terms gave no results.")
|
||||||
|
except:
|
||||||
|
await self.bot.say("Error.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("Invalid search.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("gif [text]")
|
||||||
|
|
||||||
|
@commands.command(no_pm=True)
|
||||||
|
async def gifr(self, *text):
|
||||||
|
""" gifr [keyword] - retrieves a random gif from a giphy search """
|
||||||
|
random.seed()
|
||||||
|
if len(text) > 0:
|
||||||
|
if len(text[0]) > 1 and len(text[0]) < 20:
|
||||||
|
try:
|
||||||
|
msg = "+".join(text)
|
||||||
|
search = "http://api.giphy.com/v1/gifs/search?q=" + msg + "&api_key=dc6zaTOxFJmzC"
|
||||||
|
async with aiohttp.get(search) as r:
|
||||||
|
result = await r.json()
|
||||||
|
if result["data"] != []:
|
||||||
|
maxarray = len(result)
|
||||||
|
url = result["data"][random.randint(0,maxarray)]["url"]
|
||||||
|
await self.bot.say(url)
|
||||||
|
else:
|
||||||
|
await self.bot.say("Your search terms gave no results.")
|
||||||
|
except:
|
||||||
|
await self.bot.say("Error.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("Invalid search.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("gif [text]")
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Image(bot))
|
||||||
Loading…
x
Reference in New Issue
Block a user