dragon-bot/app/dragon-bot-updated.py

109 lines
2.5 KiB
Python

import os
import random
from discord.ext import commands
TOKEN = os.getenv('token')
bot = commands.Bot(command_prefix='!')
@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='corona')
async def corona(ctx):
import corona
result = corona.parse_message(ctx.message.content)
await ctx.send(embed=result)
@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='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)