mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Added and imgur command, almost a direct port from the not so modular branch.
Command is to be expanded, this is a test.
This commit is contained in:
parent
6527e026ae
commit
b8d236d5a3
@ -6,6 +6,7 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from imgurpython import ImgurClient
|
||||||
|
|
||||||
settings = {"POLL_DURATION" : 60}
|
settings = {"POLL_DURATION" : 60}
|
||||||
|
|
||||||
@ -174,6 +175,24 @@ class General:
|
|||||||
except:
|
except:
|
||||||
await self.bot.say("Error.")
|
await self.bot.say("Error.")
|
||||||
|
|
||||||
|
@commands.command(no_pm=True)
|
||||||
|
async def imgur(self, *text):
|
||||||
|
"""Retrieves a random imgur picture.
|
||||||
|
If a link combination e.g. As3DsA4 is provided it will try to retrieve that image."""
|
||||||
|
imgurclient = ImgurClient("", "")
|
||||||
|
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 == "viral top":
|
||||||
|
items = imgurclient.gallery(section='hot', sort='viral', page=0, window='day', show_viral=True)
|
||||||
|
await self.bot.say(items[0].link)
|
||||||
|
await self.bot.say(items[1].link)
|
||||||
|
await self.bot.say(items[2].link)
|
||||||
|
else:
|
||||||
|
item = imgurclient.get_image(text)
|
||||||
|
await self.bot.say(item.link)
|
||||||
|
|
||||||
@commands.command(pass_context=True, no_pm=True)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def poll(self, ctx, *text):
|
async def poll(self, ctx, *text):
|
||||||
"""Starts/stops a poll
|
"""Starts/stops a poll
|
||||||
@ -188,7 +207,7 @@ class General:
|
|||||||
return
|
return
|
||||||
if not self.getPollByChannel(message):
|
if not self.getPollByChannel(message):
|
||||||
p = NewPoll(message, self)
|
p = NewPoll(message, self)
|
||||||
if p.valid:
|
if p.valid:
|
||||||
self.poll_sessions.append(p)
|
self.poll_sessions.append(p)
|
||||||
await p.start()
|
await p.start()
|
||||||
else:
|
else:
|
||||||
@ -213,7 +232,7 @@ class General:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async def check_poll_votes(self, message):
|
async def check_poll_votes(self, message):
|
||||||
if message.author.id != self.bot.user.id:
|
if message.author.id != self.bot.user.id:
|
||||||
if self.getPollByChannel(message):
|
if self.getPollByChannel(message):
|
||||||
self.getPollByChannel(message).checkAnswer(message)
|
self.getPollByChannel(message).checkAnswer(message)
|
||||||
|
|
||||||
@ -228,7 +247,7 @@ class NewPoll():
|
|||||||
msg = msg.split(";")
|
msg = msg.split(";")
|
||||||
if len(msg) < 2: # Needs at least one question and 2 choices
|
if len(msg) < 2: # Needs at least one question and 2 choices
|
||||||
self.valid = False
|
self.valid = False
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
self.valid = True
|
self.valid = True
|
||||||
self.already_voted = []
|
self.already_voted = []
|
||||||
@ -274,4 +293,4 @@ class NewPoll():
|
|||||||
def setup(bot):
|
def setup(bot):
|
||||||
n = General(bot)
|
n = General(bot)
|
||||||
bot.add_listener(n.check_poll_votes, "on_message")
|
bot.add_listener(n.check_poll_votes, "on_message")
|
||||||
bot.add_cog(n)
|
bot.add_cog(n)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user