qrm2/exts/fun.py

58 lines
1.8 KiB
Python
Raw Normal View History

2019-10-04 20:19:31 -04:00
"""
Fun extension for qrm
2019-10-04 20:19:31 -04:00
---
2019-10-05 02:23:11 -04:00
Copyright (C) 2019 Abigail Gold, 0x5c
2019-10-04 20:19:31 -04:00
This file is part of discord-qrm2 and is released under the terms of the GNU
2019-10-05 02:23:11 -04:00
General Public License, version 2.
2019-10-04 20:19:31 -04:00
"""
import random
2019-10-04 20:19:31 -04:00
import discord.ext.commands as commands
import common as cmn
2019-10-04 20:19:31 -04:00
class FunCog(commands.Cog):
def __init__(self, bot: commands.Bot):
2019-10-04 20:19:31 -04:00
self.bot = bot
with open('resources/words') as words_file:
self.words = words_file.read().lower().splitlines()
2019-10-04 20:19:31 -04:00
@commands.command(name="xkcd", aliases=['x'], category=cmn.cat.fun)
async def _xkcd(self, ctx: commands.Context, number: str):
2019-10-04 20:19:31 -04:00
'''Look up an xkcd by number.'''
await ctx.send('http://xkcd.com/' + number)
2019-10-04 20:19:31 -04:00
@commands.command(name="tar", category=cmn.cat.fun)
async def _tar(self, ctx: commands.Context):
2019-10-04 20:19:31 -04:00
'''Returns an xkcd about tar.'''
await ctx.send('http://xkcd.com/1168')
@commands.command(name="xd", hidden=True, category=cmn.cat.fun)
async def _xd(self, ctx: commands.Context):
2019-10-04 20:19:31 -04:00
'''ecks dee'''
await ctx.send('ECKS DEE :smirk:')
@commands.command(name="funetics", aliases=['fun'], category=cmn.cat.fun)
async def _funetics_lookup(self, ctx: commands.Context, *, msg: str):
'''Get fun phonetics for a word or phrase.'''
with ctx.typing():
result = ''
for char in msg.lower():
if char.isalpha():
result += random.choice([word for word in self.words if word[0] == char])
else:
result += char
result += ' '
embed = cmn.embed_factory(ctx)
embed.title = f'Funetics for {msg}'
embed.description = result.title()
embed.colour = cmn.colours.good
await ctx.send(embed=embed)
2019-10-04 20:19:31 -04:00
def setup(bot: commands.Bot):
2019-10-04 20:19:31 -04:00
bot.add_cog(FunCog(bot))