Skip to content

Instantly share code, notes, and snippets.

@polyjitter
Last active October 19, 2018 19:29
Show Gist options
  • Save polyjitter/8fc9ead57c85bf45e2cae98041e4b656 to your computer and use it in GitHub Desktop.
Save polyjitter/8fc9ead57c85bf45e2cae98041e4b656 to your computer and use it in GitHub Desktop.
import discord
from discord.ext import commands
import duckduckgo as ddg
import traceback
class ChatGenie():
def __init__(self, bot):
self.bot = bot
self.kaomoji_dict = bot.kaomoji_dict
@commands.command(name='me', aliases=['say', 'do', 'rp', 'pretend', 'becauseihaveasadlife'], pass_context=True)
async def me(self, ctx, *, action: str):
'''Makes me pretend to do something for once in my life.'''
message = ctx.message
if message.channel.is_private:
me_color = discord.Color.default()
me_name = self.bot.user.name
else:
me_color = message.server.me.color
me_name = message.server.me.display_name
await self.bot.delete_message(message)
await self.bot.say(embed = discord.Embed(color = me_color, description = "_**{}** {}_".format(me_name, action)))
@commands.command(name='quote', aliases=['take', 'claim', ':eyes:'], pass_context=True)
async def quote(self, ctx, *, messageid: str):
'''I see you there.'''
try:
quoted_message = discord.utils.get(self.bot.messages, id=messageid)
except Exception as e:
error_embed = discord.Embed(color = 15746887,
description = "**{}**: _{}_".format(e.__class__.__name__, str(e)))
traceback.print_exc()
await self.bot.say(embed = error_embed)
return
if quoted_message is None:
error_embed = discord.Embed(color = 15746887,
description = "**Error:**: _Message was embed only or not found._")
await self.bot.say(embed = error_embed)
return
if quoted_message.channel.is_private:
quoted_color = discord.Color.default()
else:
quoted_color = quoted_message.author.color
quote_embed = discord.Embed(color = quoted_color,
description = '"{}"'.format(quoted_message.content))
if quoted_message.channel.is_private or not quoted_message.author.nick:
quoted_name = quoted_message.author.name
else:
quoted_name = quoted_message.author.nick
quote_embed.set_author(name = "{} once said...".format(quoted_name),
icon_url = quoted_message.author.avatar_url)
if not quoted_message.channel.is_private:
quote_embed.set_footer(text = quoted_message.server.name,
icon_url = quoted_message.server.icon_url)
await self.bot.delete_message(ctx.message)
await self.bot.say(embed=quote_embed)
@commands.command(name='search', aliases=['duckduckgo', 'ddg', 'bang'], pass_context=True)
async def ddg_search(self, ctx, *, query: str):
'''Searches ddg...'''
result = ddg.query(query)
result_embed = discord.Embed(color = 14571571,
title = result.heading)
if result.redirect.url is not "":
result_embed.description = result.redirect.url
elif result.answer.text is not "":
result_embed.description = "_{}_".format(result.answer.text)
elif result.abstract.text is not "":
result_embed.description = "{}".format(result.abstract.text)
result_embed.url = result.abstract.url
result_embed.set_thumbnail(url=result.image.url)
elif len(result.related) is not 0:
disambig = ""
for entry in result.related:
try:
disambig += "{}\n\n".format(entry.text)
except:
continue
disambig = disambig.rstrip("\n\n")
result_embed.description = "**Did you mean:**\n\n_{}_".format(disambig)
else:
result_embed.description = ddg.get_zci(query)
result_embed.description += "\n\n[`Show more results...`]({})".format("https://duckduckgo.com/?q={}"
.format(query.replace(" ", "%20")
.replace("(", "%28")
.replace(")", "%29")))
result_embed.set_footer(text="Powered by DuckDuckGo",
icon_url = "https://duckduckgo.com/favicon.ico")
await self.bot.say(embed=result_embed)
@commands.command(name='kaomoji', aliases=['textmoji', 'shortcuts', 'crappymemes'])
async def kaomoji_ref(self):
'''Lists all my custom textbased emojis.'''
kaomoji_embed = discord.Embed(description='_You currently have {} kaomojis._'.format(len(self.kaomoji_dict)))
for kaomoji in self.kaomoji_dict:
kaomoji_embed.add_field(name=kaomoji,
value=self.kaomoji_dict[kaomoji])
await self.bot.say(embed=kaomoji_embed)
def setup(bot):
bot.add_cog(ChatGenie(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment