-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
45 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,30 @@ | ||
from discord import Embed | ||
|
||
from discord.ext import commands, tasks | ||
from discord.ext import commands | ||
from discord.ext.commands import Context | ||
|
||
import aiohttp | ||
|
||
from .utils.colo import COLOR | ||
|
||
# Map of channel IDs to tasks.Loop automeme loops | ||
automeme_loops = {} | ||
|
||
class Meme(commands.Cog): | ||
def __init__(self, client): | ||
self.client = client | ||
|
||
async def automeme_routine(ctx: Context): | ||
'''sends a meme every 10 mins''' | ||
async with aiohttp.ClientSession() as session: | ||
url = "https://meme-api.herokuapp.com/gimme" | ||
async with session.get(url) as response: | ||
@commands.command(aliases=['meme']) | ||
async def memes(self, ctx: Context, param: str = None): | ||
sub = '/' if param is None else '/' + str(param) | ||
url = "https://meme-api.herokuapp.com/gimme" + sub | ||
async with self.client.HTTP_SESSION.get(url) as response: | ||
response = await response.json() | ||
embed = Embed( | ||
title=response['title'], | ||
url=response['postLink'], | ||
color=COLOR.JOY) | ||
embed.set_image(url=response['url']) | ||
embed.set_footer( | ||
text=f"r/{response['subreddit']} | Requested by {ctx.author.name}") | ||
txt = f"r/{response['subreddit']} | Requested by {ctx.author.name}" | ||
embed.set_footer(text=txt) | ||
await ctx.send(embed=embed) | ||
|
||
|
||
class Meme(commands.Cog): | ||
def __init__(self, client): | ||
self.client = client | ||
|
||
@commands.command(aliases=['meme']) | ||
async def memes(self, ctx: Context, param: str = None): | ||
sub = '/' if param is None else '/' + str(param) | ||
async with aiohttp.ClientSession() as session: | ||
url = "https://meme-api.herokuapp.com/gimme" + sub | ||
async with session.get(url) as response: | ||
response = await response.json() | ||
embed = Embed( | ||
title=response['title'], | ||
url=response['postLink'], | ||
color=COLOR.JOY) | ||
embed.set_image(url=response['url']) | ||
txt = f"r/{response['subreddit']} | Requested by {ctx.author.name}" | ||
embed.set_footer(text=txt) | ||
await ctx.send(embed=embed) | ||
|
||
@commands.command() | ||
async def automeme(self, ctx: Context): | ||
'''Triggers the automeme taskloop for the channel context''' | ||
channel_id = ctx.channel.id | ||
if channel_id in automeme_loops: | ||
await ctx.send('Automeme already running here') | ||
else: | ||
# using decorator instead of tasks.Loop directly to preserve | ||
# default arguments | ||
loop = tasks.loop(seconds=600)(automeme_routine) | ||
automeme_loops[channel_id] = loop | ||
loop.start(ctx) | ||
|
||
@commands.command() | ||
async def automeme_cancel(self, ctx: Context): | ||
'''Cancel the Automeme task in the current channel''' | ||
channel_id = ctx.channel.id | ||
if channel_id not in automeme_loops: | ||
await ctx.send('Automeme not running here') | ||
else: | ||
automeme_loops[channel_id].cancel() | ||
del automeme_loops[channel_id] | ||
await ctx.send('Automeme canceled here') | ||
|
||
|
||
def setup(client): | ||
client.add_cog(Meme(client)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters