Skip to content

Commit

Permalink
refactor: linted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyvy-vi committed Apr 4, 2021
1 parent 4855d35 commit 0c107d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 43 deletions.
44 changes: 1 addition & 43 deletions bot/cogs/meme.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
from discord import Embed

from discord.ext import commands, tasks
from discord.ext import commands
from discord.ext.commands import Context

from .utils.colo import COLOR

# Map of channel IDs to tasks.Loop automeme loops
automeme_loops = {}


async def automeme_routine(ctx: Context):
'''sends a meme every 10 mins'''
url = "https://meme-api.herokuapp.com/gimme"
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}")
await ctx.send(embed=embed)


class Meme(commands.Cog):
def __init__(self, client):
Expand All @@ -43,30 +25,6 @@ async def memes(self, ctx: Context, param: str = None):
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))
3 changes: 3 additions & 0 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# status-change-cycle(The bot changes presence after a few mins.)

_close = client.close


async def close():
logger.info('Logging out...')
await _close()
Expand Down Expand Up @@ -96,6 +98,7 @@ async def on_ready():
client.HTTP_SESSION = ClientSession()
# client.user gives the bots discord username tag


# discord.py has an inbuilt help command, which doesn't look good''
@tasks.loop(seconds=600)
async def change_status():
Expand Down

0 comments on commit 0c107d4

Please sign in to comment.