186 lines
4.4 KiB
Python
186 lines
4.4 KiB
Python
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!')
|
|
|
|
# @bot.event
|
|
# async def on_member_join(member):
|
|
# await member.create_dm()
|
|
# await member.dm_channel.send(
|
|
# f'Hi {member.name}, welcome to my ths server!'
|
|
# )
|
|
|
|
|
|
@bot.command(name='invite')
|
|
async def invite(ctx):
|
|
# Default to creating the invite to the #general channel
|
|
# if the user is in a voice channel, try to create the invite there
|
|
invite_channel = ctx.message.channel
|
|
try:
|
|
if ctx.message.author.voice.channel:
|
|
invite_channel = ctx.message.author.voice.channel
|
|
except AttributeError:
|
|
pass
|
|
invite = await invite_channel.create_invite(
|
|
destination=invite_channel,
|
|
max_uses=1,
|
|
max_age=3600
|
|
)
|
|
await ctx.send(invite)
|
|
|
|
@bot.command(name='redpanda')
|
|
async def redpanda(ctx):
|
|
|
|
import animals
|
|
await ctx.send(animals.get_red_panda())
|
|
|
|
@bot.command(name='dog')
|
|
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
|
|
await ctx.send(animals.get_birb())
|
|
|
|
@bot.command(name='corona')
|
|
async def corona(ctx):
|
|
|
|
import corona
|
|
result = corona.parse_message(ctx.message.content)
|
|
|
|
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):
|
|
|
|
import stock
|
|
result = stock.parse_message(ctx.message.content)
|
|
|
|
await ctx.send(embed=result)
|
|
|
|
@bot.command(name='flows')
|
|
async def flows(ctx):
|
|
|
|
import river_stats
|
|
result = river_stats.get_stats()
|
|
|
|
await ctx.send(result)
|
|
|
|
@bot.command(name='8ball')
|
|
async def eight_ball(ctx):
|
|
|
|
import eight_ball
|
|
result = eight_ball.check_8ball(ctx.message.content)
|
|
|
|
await ctx.send(result)
|
|
|
|
@bot.command(name='ffxiv')
|
|
async def ffxiv(ctx):
|
|
import ffxiv
|
|
try:
|
|
ffxiv_embed = ffxiv.parse_message(ctx.message.content)
|
|
await ctx.send(embed=ffxiv_embed)
|
|
except Exception:
|
|
await ctx.send('I encountered an error while searching for that player')
|
|
|
|
|
|
@bot.command(name='purge')
|
|
async def purge(ctx):
|
|
def is_me(m):
|
|
return m.author == ctx.message.author
|
|
|
|
num = 20
|
|
if len(ctx.message.content.split()) > 1:
|
|
try:
|
|
num = int(ctx.message.content.split()[1]) + 1
|
|
except ValueError:
|
|
await ctx.send(
|
|
ctx.message.channel,
|
|
"You need to give me a number, you entered {}".format(
|
|
ctx.message.content.split()[1]
|
|
)
|
|
)
|
|
return
|
|
await ctx.message.channel.purge(limit=num, check=is_me)
|
|
|
|
@bot.command(name='cleanup')
|
|
async def cleanup(ctx):
|
|
def is_discord_bot(m):
|
|
return m.author == bot.user
|
|
|
|
num = 20
|
|
if len(ctx.message.content.split()) > 1:
|
|
try:
|
|
num = int(ctx.message.content.split()[1]) + 1
|
|
except ValueError:
|
|
await ctx.send(
|
|
ctx.message.channel,
|
|
"You need to give me a number, you entered {}".format(
|
|
ctx.message.content.split()[1]
|
|
)
|
|
)
|
|
return
|
|
await ctx.message.channel.purge(limit=num, check=is_discord_bot)
|
|
|
|
bot.run(TOKEN)
|