adding define, generate_embed helper, and greentext. fixes #8 #12 #7

This commit is contained in:
Luke Robles 2020-08-08 21:30:59 -07:00
parent 6d74f4c24b
commit 13e23c946a

View File

@ -1,11 +1,37 @@
import os
import random
import discord
from discord.ext import commands
TOKEN = os.getenv('token')
bot = commands.Bot(command_prefix='!')
def generate_embed(embed_url=None, embed_title=None, embed_description=None, embed_color=None):
"""
generate_embed(embed_url=None, embed_title=None, embed_description=None, embed_color=None)
Generates a discord embed object based on the URL passed in
Optionally, you can set the title and description text for the embed object.
"""
if not embed_description and embed_url:
embed_description="[Direct Link]({})".format(embed_url)
if not embed_color:
embed_color=discord.Color.gold()
embed = discord.Embed(
title=embed_title,
description=embed_description,
color=embed_color,
type='rich'
)
if embed_url:
embed.set_image(url=embed_url)
return embed
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
@ -47,6 +73,24 @@ async def dog(ctx):
import animals
await ctx.send(animals.get_dog())
@bot.command(name='define')
async def define(ctx):
import define_word
await ctx.send(define_word.get_definition(ctx.message.content))
@bot.command(name='greentext')
async def greentext(ctx):
import get_from_reddit
await ctx.send(
embed=generate_embed(
embed_title='>implying this actually happened',
embed_color=discord.Color.green(),
embed_url=get_from_reddit.get_image(boards=['classic4chan', 'greentext', '4chan'])
)
)
@bot.command(name='birb')
async def birb(ctx):
import animals
@ -60,6 +104,12 @@ async def corona(ctx):
await ctx.send(embed=result)
@bot.command(name='decide')
async def decide(ctx):
import decide
await ctx.send(decide.decide(ctx.message.content))
@bot.command(name='stock')
async def stock(ctx):