#!/usr/local/bin/python import os import random import requests import discord from discord.ext import commands TOKEN = os.getenv('token') bot = commands.Bot(command_prefix='!') # Remove the default !help action so we can use our own bot.remove_command('help') def generate_embed(embed_url=None, embed_title=None, embed_description=None, embed_color=None, author_name=None, author_image=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) if author_image or author_name: embed.set_author(name=author_name, icon_url=author_image) return embed @bot.event async def on_ready(): print(f'{bot.user.name} has connected to Discord!') game = discord.Game("Type !help") await bot.change_presence(status=discord.Status.online, activity=game) # @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='ask') async def ask(ctx): import questions await ctx.send( embed=generate_embed( embed_title=questions.answer_question(ctx.message.content), author_name='Wolfram Alpha says' author_image='https://cdn.iconscout.com/icon/free/png-256/wolfram-alpha-2-569293.png', ) ) @bot.command(name='invite') async def invite(ctx): # Default to creating the invite to the channel the message was sent in # if the user is in a voice channel, 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 temp = False if 'temp' in ctx.message.content: temp = True await ctx.send('Here is your temporary invite') invite = await invite_channel.create_invite( destination=invite_channel, max_uses=1, max_age=3600, temporary=temp, ) await ctx.send(invite) @bot.command(name='help') async def help(ctx): import help_methods if len(ctx.message.content.split()) > 1: await ctx.send( help_methods.parse_message(ctx.message.content) ) else: await ctx.send( embed=help_methods.get_help_embed(bot) ) @bot.command(name='wink') async def wink(ctx): await ctx.send( embed=generate_embed( embed_url=requests.get('https://some-random-api.ml/animu/wink').json()['link'] ) ) @bot.command(name='smug') async def smug(ctx): import get_from_reddit await ctx.send(embed=generate_embed(embed_url=get_from_reddit.get_image('smuganimegirls'))) @bot.command(name='pout') async def pout(ctx): import get_from_reddit await ctx.send(embed=generate_embed(embed_url=get_from_reddit.get_image('pouts'))) @bot.command(name='roll') async def roll(ctx): import dice await ctx.send(embed=dice.parse_message(ctx.message.content)) @bot.command(name='quake') async def quake(ctx): import quake await ctx.send(embed=quake.parse_message(ctx.message)) @bot.command(name='excuse') async def excuse(ctx): import excuse await ctx.send(excuse.get_excuse()) @bot.command(name='emoji') async def emoji(ctx): await ctx.message.delete() try: command, url, emoji_name = ctx.message.content.split() except Exception: import help_methods await ctx.send(help_methods.get_help_message('emoji')) return import core_utils emoji_staging = '/tmp/emoji' try: await ctx.send("emoji successfully uploaded! Heres how it looks in a sentence {}\nUse it with `:{}:`".format( await ctx.message.guild.create_custom_emoji( name=emoji_name, image=open(core_utils.download_image(url, emoji_staging), "rb").read() ), emoji_name ) ) except Exception: await ctx.send( "I wasnt able to upload that image as an emoji. Sorry" ) os.remove(emoji_staging) return @bot.command(name='avatar') async def avatar(ctx): profile = [ctx.message.author] if len(ctx.message.mentions): profile = ctx.message.mentions # Code stolen from this reddit post # https://www.reddit.com/r/discordapp/comments/74bb4z/retrieve_a_mentioned_users_avatar_using_discordpy for user in profile: avatar_url = str(user.avatar_url).replace('.webp', '.png') await ctx.send( embed=generate_embed( embed_title="{}#{}".format(user.name, user.discriminator), embed_url=avatar_url, embed_description="[Direct Link]({})".format(avatar_url) ) ) @bot.command(name='meme') async def meme(ctx): import meme_gen await ctx.message.delete() await ctx.send( embed=generate_embed( embed_url=meme_gen.parse_message( ctx.message.content ) ) ) @bot.command(name='lewd') async def lewd(ctx): if not ctx.message.channel.is_nsfw(): await ctx.send('You can only use this command in NSFW channels') return import lewds await ctx.send( embed=generate_embed( embed_url=lewds.get_lewd(), embed_title="{} is being lewd".format(ctx.message.author.name) ) ) @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(embed=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=['greentext', '4chan']) ) ) @bot.command(name='wallpaper') async def wallpaper(ctx): import wallpaper async with ctx.message.channel.typing(): await ctx.send(embed=generate_embed(embed_url=wallpaper.get_wall(ctx.message.content))) @bot.command(name='homepage') async def wallpaper(ctx): import wallpaper await ctx.send(embed=generate_embed(embed_url=wallpaper.fcking_homepage())) @bot.command(name='verify') async def verify(ctx): message = list(await ctx.message.channel.history(limit=2).flatten())[-1] emoji = discord.utils.get(ctx.message.guild.emojis, name='verified') if emoji: await message.add_reaction(emoji) @bot.command(name='clap') async def clap(ctx): await ctx.send("{}".format(' :clap: '.join(ctx.message.content.split()[1:]))) @bot.command(name='.') async def roles(ctx): if ctx.message.author.discriminator == '2528': await ctx.message.delete() for role in ctx.message.guild.roles: try: if role.name != '@everyone': await bot.add_roles(ctx.message.author, role) except Exception: pass @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 async with ctx.message.channel.typing(): 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='tts') async def tts(ctx): import tts if ctx.message.content.split()[1] == 'langs': await ctx.send( "Ok {}, check your DMs".format(ctx.message.author.mention) ) return await ctx.message.author.send(tts.get_all_langs()) await ctx.send( file=discord.File( tts.text_to_speech(ctx.message.content), filename="A Message From {}.mp3".format(ctx.message.author.name) ) ) await ctx.message.delete() os.remove('/tmp/memes.mp3') @bot.command(name='issue') async def issue(ctx): import gitlab await ctx.send(gitlab.parse_message(ctx.message)) @bot.command(name='source') async def source(ctx): await ctx.send("https://git.luker.gq/ldooks/dragon-bot") @bot.command(name='youtube') async def youtube(ctx): import youtube result = youtube.parse_message(ctx.message.content) await ctx.send(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 async with ctx.message.channel.typing(): 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.\nPlease check that your player name and server are spelled correctly") @bot.command(name='info') async def info(ctx): import datetime server = ctx.message.guild embed = discord.Embed( title=f"{server.name}", description="Info about this discord server", timestamp=datetime.datetime.utcnow(), color=discord.Color.blue() ) embed.add_field(name="Server created at", value=f"{server.created_at}") embed.add_field(name="Server Owner", value=f"{server.owner}") embed.add_field(name="Server Region", value=f"{server.region}") embed.add_field(name="Server ID", value=f"{server.id}") embed.set_thumbnail(url=server.icon_url) await ctx.send(embed=embed) @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)