#!/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 #### a bunch of silly functions that will listen for messages with specific content @bot.listen("on_message") async def fix_cdn_url(ctx): if "media.discordapp.net" in ctx.content: await ctx.delete() await ctx.channel.send( "%s said:\n%s" % ( ctx.author.mention, ctx.content.replace("media.discordapp.net", "cdn.discordapp.com"), ) ) return # @bot.listen('on_message') # async def react_with_dale(ctx): # if 'dale' in ctx.content.lower(): # emoji = discord.utils.get(ctx.guild.emojis, name='dale') # if emoji: # await ctx.add_reaction(emoji) # return @bot.listen("on_message") async def convert_heic_to_jpg(ctx): from wand.image import Image if ctx.attachments: for attachment in ctx.attachments: if attachment.filename.lower().endswith("heic"): heic_file = "/tmp/heic" jpg_file = "/tmp/jpg.jpg" await attachment.save(fp=heic_file) # Convert heic to jpg img = Image(filename=heic_file) img.format = "jpg" img.save(filename=jpg_file) img.close() try: await ctx.delete() except Exception: pass await ctx.channel.send( "%s said:\n%s" % (ctx.author.mention, ctx.content), file=discord.File(jpg_file), ) return @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=discord.Activity( type=discord.ActivityType.listening, name="type !help" ), ) await bot.get_channel(152921472304676865).send("I have reconnected") @bot.command(name="shoo") async def shoo(ctx): if ctx.message.author.id != 144986109804412928: return await ctx.message.delete() await ctx.message.guild.leave() @bot.command(name="ask") async def ask(ctx): import questions await ctx.send( questions.answer_question(ctx.message.content), ) @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.author.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("Check your DMs") await ctx.author.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="owo") async def owo(ctx): from owotext import OwO uwu = OwO() await ctx.send(uwu.whatsthis(" ".join(ctx.message.content.split()[1:]))) @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 for user in profile: avatar_url = user.avatar_url_as(static_format="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="panda") async def panda(ctx): import animals await ctx.send(animals.get_panda()) @bot.command(name="koala") async def koala(ctx): import animals await ctx.send(animals.get_koala()) @bot.command(name="racoon") async def racoon(ctx): import animals await ctx.send(animals.get_racoon()) @bot.command(name="fox") async def fox(ctx): import animals await ctx.send(animals.get_fox()) @bot.command(name="cat") async def cat(ctx): import animals await ctx.send(animals.get_cat()) @bot.command(name="kangaroo") async def kangaroo(ctx): import animals await ctx.send(animals.get_kangaroo()) @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", "newgreentexts", "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="trackdays") async def trackdays(ctx): role = discord.utils.find( lambda r: r.name == "Track day gamers", ctx.message.guild.roles ) if role not in ctx.message.author.roles: return await ctx.send("You cant do that") import trackdays for track, events in trackdays.get_msreg().items(): embed = discord.Embed( description=":checkered_flag: **Upcoming events at %s**:checkered_flag: " % track, color=0x428BCA, type="rich", ) for track_day in events: embed.add_field( name="-------------\n**Event Name**", value=track_day["event_name"], inline=False, ) embed.add_field(name="Date", value=track_day["event_date"], inline=False) embed.add_field( name="Event URL", value=track_day["event_url"], inline=False ) await ctx.send(embed=embed) @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="simp") async def simp(ctx): if len(ctx.message.content.split()) == 1: return await ctx.send("You must provide a link to an image") response = requests.get( "https://some-random-api.ml/canvas/simpcard/?avatar=%s" % ctx.message.content.split()[-1] ) with open("/app/simp.jpg", "wb") as f: f.write(response.content) await ctx.message.delete() await ctx.send(file=discord.File("/app/simp.jpg")) @bot.command(name="horny") async def horny(ctx): if len(ctx.message.content.split()) == 1: return await ctx.send("You must provide a link to an image") response = requests.get( "https://some-random-api.ml/canvas/horny/?avatar=%s" % ctx.message.content.split()[-1] ) with open("/app/horny.jpg", "wb") as f: f.write(response.content) await ctx.message.delete() await ctx.send(file=discord.File("/app/horny.jpg")) @bot.command(name="wasted") async def wasted(ctx): if len(ctx.message.content.split()) == 1: return await ctx.send("You must provide a link to an image") response = requests.get( "https://some-random-api.ml/canvas/wasted/?avatar=%s" % ctx.message.content.split()[-1] ) with open("/app/wasted.jpg", "wb") as f: f.write(response.content) await ctx.message.delete() await ctx.send(file=discord.File("/app/wasted.jpg")) @bot.command(name="birb") async def birb(ctx): import animals await ctx.send(animals.get_birb()) @bot.command(name="dale") async def dale(ctx): import animals # If the file picked is too large, try again dale_pic = None while not dale_pic: try: dale_pic = animals.dale() await ctx.send(file=discord.File(dale_pic)) except Exception: print("File too large, trying again") dale_pic = None @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="rat") async def rat(ctx): import animals await ctx.send(animals.get_rat()) @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()) file_path = tts.text_to_speech(ctx.message.content) await ctx.send( file=discord.File( file_path, filename="A Message From {}.mp3".format(ctx.message.author.name) ) ) await ctx.message.delete() os.remove(file_path) @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(embed=result) @bot.command(name="nft") async def nft(ctx): import nft result = nft.get_nft() 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(":8ball: %s :8ball:" % result) @bot.command(name="bf5") async def bf5(ctx): import bf5 try: await ctx.send(embed=bf5.get_player(ctx.message.content.split()[1])) except Exception: await ctx.send( "I encountered an error while searching for that player.\nPlease check that your player name is spelled correctly" ) @bot.command(name="ffxiv") async def ffxiv(ctx): import ffxiv async with ctx.message.channel.typing(): try: await ctx.send(embed=ffxiv.parse_message(ctx.message.content)) 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.add_field( name="You've been a member of this server since:", value=ctx.message.author.joined_at.strftime("%A, %m-%d-%Y"), inline=False, ) embed.add_field( name="Servers using Dragon bot", value="\n".join(x.name for x in bot.guilds) ) 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) await ctx.message.delete() @bot.event async def on_command_completion(ctx): channel = bot.get_channel(826547484632678453) embed = discord.Embed(colour=discord.Color.green(), title="Command Executed") embed.add_field(name="Command:", value=f"`{ctx.command}`") embed.add_field(name="User:", value=f"`{ctx.author}`", inline=False) embed.add_field(name="Channel:", value=f"{ctx.channel} **( <#{ctx.channel.id}> )**") embed.add_field( name="Link to Message:", value="**(** [%s](%s) **)**" % (ctx.channel, ctx.message.jump_url), ) embed.add_field(name="Server:", value=f"{ctx.guild} **( <#{ctx.channel.id}> )**") if ctx.message.author.id != 144986109804412928: await channel.send(embed=embed) bot.run(TOKEN)