From 74856a2bf5058b71bea36a77c8910bbecf1a343b Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Fri, 29 Apr 2022 11:31:09 -0700 Subject: [PATCH] Leveraging cogs finally. bot.py is way smaller now --- app/bot.py | 679 +---------------------------------- app/cogs/actual_utils.py | 108 ++++++ app/cogs/animal_functions.py | 83 +++++ app/cogs/cheeky_functions.py | 168 +++++++++ app/cogs/game_apis.py | 36 ++ app/cogs/server_utils.py | 186 ++++++++++ app/cogs/user_functions.py | 23 ++ app/cogs/weeb_shit.py | 62 ++++ app/core_utils.py | 34 ++ app/dice.py | 15 - app/help_methods.py | 3 +- app/wallpaper.py | 17 - helm/values.yaml | 3 +- 13 files changed, 715 insertions(+), 702 deletions(-) create mode 100644 app/cogs/actual_utils.py create mode 100644 app/cogs/animal_functions.py create mode 100644 app/cogs/cheeky_functions.py create mode 100644 app/cogs/game_apis.py create mode 100644 app/cogs/server_utils.py create mode 100644 app/cogs/user_functions.py create mode 100644 app/cogs/weeb_shit.py diff --git a/app/bot.py b/app/bot.py index f249fbc3..48779cec 100755 --- a/app/bot.py +++ b/app/bot.py @@ -1,8 +1,5 @@ #!/usr/local/bin/python import os -import random -import requests - import discord from discord.ext import commands @@ -12,10 +9,17 @@ intents.members = True bot = commands.Bot(command_prefix="!", intents=intents) bot.remove_command("help") +cogfiles = [ + f"cogs.{filename[:-3]}" + for filename in os.listdir("./cogs/") + if filename.endswith(".py") +] -@bot.command() -async def ping(ctx): - await ctx.send("pong") +for cogfile in cogfiles: + try: + bot.load_extension(cogfile) + except Exception as e: + print(e) @bot.event @@ -28,43 +32,10 @@ async def on_ready(): type=discord.ActivityType.listening, name="type !help" ), ) - await bot.get_channel(152921472304676865).send("I have reconnected") + if not os.getenv("DRAGON_ENV") == "test": + await bot.get_channel(152921472304676865).send("I have reconnected") -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): # Ignore images @@ -112,632 +83,6 @@ async def convert_heic_to_jpg(ctx): return -@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, url, emoji_name): - await ctx.message.delete() - 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, user: discord.Member): - await ctx.send( - embed=generate_embed( - embed_title="{}#{}".format(user.name, user.discriminator), - embed_url=user.avatar, - embed_description="[Direct Link]({})".format(user.avatar), - ) - ) - - -@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="sheeb", - aliases=["shiba", "shib", "shoob", "sheeber", "shoober", "shobe", "shibe"], -) -async def dog(ctx): - - import animals - - await ctx.send(animals.random_sheeb()) - - -@bot.command(name="define", aliases=["ud"]) -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): - content = ctx.message.content.split()[1:] - if len(content) == 1: - content = [char for char in content[0]] - await ctx.send("{}".format(" :clap: ".join(content))) - - -@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="send") -async def send(ctx): - if ctx.message.author.discriminator == "2528": - await bot.get_channel(152921472304676865).send( - " ".join(ctx.message.content.split()[1:]) - ) - - -@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): - - msg = ctx.message.content - if len(msg.split()) < 2: - import help_methods - - await ctx.send(help_methods.get_help_message("stock")) - - import stock - - results = stock.parse_message(msg) - for res in results: - await ctx.send(embed=res) - - -@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() -async def timeout(ctx, user: discord.Member = None, time=None, *, reason=None): - if not ctx.message.author.discriminator in ["2528", "4082"]: - return - - import humanfriendly - import datetime - - time = humanfriendly.parse_timespan(time) - await user.timeout(until=discord.utils.utcnow() + datetime.timedelta(seconds=time)) - await user.send("You have been timed out for %s seconds for %s" % (time, reason)) - await ctx.send("Timed %s out for %s seconds" % (user.mention, time)) - - -@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", aliases=["yt"]) -async def youtube(ctx, *, query): - import re - from urllib import parse, request - - query_string = parse.urlencode({"search_query": query}) - html_content = request.urlopen("http://www.youtube.com/results?" + query_string) - search_results = re.findall("\/watch\?v=(.{11})", html_content.read().decode()) - - result = "https://www.youtube.com/watch?v=" + search_results[0] - - 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, first_name, last_name, server): - import ffxiv - - async with ctx.message.channel.typing(): - try: - name = "%s %s" % (first_name, last_name) - await ctx.send(embed=ffxiv.make_request(name=name, server=server)) - 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 %s" % bot.user.name, - value="\n".join("[%s](%s)" % (x.name, x.jump_url) for x in bot.guilds), - ) - embed.set_thumbnail(url=server.icon) - - await ctx.send(embed=embed) - - -@bot.command(name="purge") -async def purge(ctx, count=None): - def is_me(m): - return m.author == ctx.message.author - - num = 20 - if count: - num = int(count) + 1 - 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) diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py new file mode 100644 index 00000000..09f0b6a6 --- /dev/null +++ b/app/cogs/actual_utils.py @@ -0,0 +1,108 @@ +from discord.ext import commands +import discord +import os +import get_from_reddit +import core_utils +import requests + + +class ActualUtils(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="youtube", aliases=["yt"]) + async def youtube(self, ctx: commands.Context, *, query): + import re + from urllib import parse, request + + query_string = parse.urlencode({"search_query": query}) + html_content = request.urlopen("http://www.youtube.com/results?" + query_string) + search_results = re.findall("\/watch\?v=(.{11})", html_content.read().decode()) + + result = "https://www.youtube.com/watch?v=" + search_results[0] + + await ctx.send(result) + + @commands.command(name="issue") + async def issue(self, ctx: commands.Context): + import gitlab + + await ctx.send(gitlab.parse_message(ctx.message)) + + @commands.command(name="tts") + async def tts(self, ctx: commands.Context): + + 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) + + @commands.command(name="trackdays") + async def trackdays(self, ctx: commands.Context): + 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) + + @commands.command(name="corona") + async def corona(self, ctx: commands.Context): + + import corona + + async with ctx.message.channel.typing(): + result = corona.parse_message(ctx.message.content) + + await ctx.send(embed=result) + + @commands.command(name="stock") + async def stock(self, ctx: commands.Context): + + msg = ctx.message.content + if len(msg.split()) < 2: + import help_methods + + await ctx.send(help_methods.get_help_message("stock")) + + import stock + + results = stock.parse_message(msg) + for res in results: + await ctx.send(embed=res) + + +def setup(bot): + bot.add_cog(ActualUtils(bot)) diff --git a/app/cogs/animal_functions.py b/app/cogs/animal_functions.py new file mode 100644 index 00000000..54a209ad --- /dev/null +++ b/app/cogs/animal_functions.py @@ -0,0 +1,83 @@ +from discord.ext import commands +import discord +import animals + + +class AnimalFunctions(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="redpanda") + async def redpanda(self, ctx: commands.Context): + + await ctx.send(animals.get_red_panda()) + + @commands.command(name="panda") + async def panda(self, ctx: commands.Context): + + await ctx.send(animals.get_panda()) + + @commands.command(name="koala") + async def koala(self, ctx: commands.Context): + + await ctx.send(animals.get_koala()) + + @commands.command(name="racoon") + async def racoon(self, ctx: commands.Context): + + await ctx.send(animals.get_racoon()) + + @commands.command(name="fox") + async def fox(self, ctx: commands.Context): + + await ctx.send(animals.get_fox()) + + @commands.command(name="cat") + async def cat(self, ctx: commands.Context): + + await ctx.send(animals.get_cat()) + + @commands.command(name="kangaroo") + async def kangaroo(self, ctx: commands.Context): + + await ctx.send(animals.get_kangaroo()) + + @commands.command(name="dog") + async def dog(self, ctx: commands.Context): + + await ctx.send(animals.get_dog()) + + @commands.command( + name="sheeb", + aliases=["shiba", "shib", "shoob", "sheeber", "shoober", "shobe", "shibe"], + ) + async def sheeb(self, ctx: commands.Context): + await ctx.send(animals.random_sheeb()) + + @commands.command(name="birb") + async def birb(self, ctx: commands.Context): + + await ctx.send(animals.get_birb()) + + @commands.command(name="dale") + async def dale(self, ctx: commands.Context): + + # 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 + + @commands.command(name="rat") + async def rat(self, ctx: commands.Context): + import animals + + await ctx.send(animals.get_rat()) + + +def setup(bot): + bot.add_cog(AnimalFunctions(bot)) diff --git a/app/cogs/cheeky_functions.py b/app/cogs/cheeky_functions.py new file mode 100644 index 00000000..93a7775f --- /dev/null +++ b/app/cogs/cheeky_functions.py @@ -0,0 +1,168 @@ +from discord.ext import commands +import core_utils +import discord + + +class Cheeky(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="decide") + async def decide(self, ctx: commands.Context): + + import decide + + await ctx.send(decide.decide(ctx.message.content)) + + @commands.command(name="simp") + async def simp(self, ctx: commands.Context): + 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")) + + @commands.command(name="horny") + async def horny(self, ctx: commands.Context): + 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")) + + @commands.command(name="wasted") + async def wasted(self, ctx: commands.Context): + 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")) + + @commands.command(name="verify") + async def verify(self, ctx: commands.Context): + 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) + + @commands.command(name="clap") + async def clap(self, ctx: commands.Context): + content = ctx.message.content.split()[1:] + if len(content) == 1: + content = [char for char in content[0]] + await ctx.send("{}".format(" :clap: ".join(content))) + + @commands.command(name="greentext") + async def greentext(self, ctx: commands.Context): + + import get_from_reddit + + await ctx.send( + embed=core_utils.generate_embed( + embed_title=">implying this actually happened", + embed_color=discord.Color.green(), + embed_url=get_from_reddit.get_image( + boards=["greentext", "newgreentexts", "4chan"] + ), + ) + ) + + @commands.command(name="roll") + async def roll( + self, ctx: commands.Context, number_of_die, sides, number_to_add=None + ): + import dice + + sides = sides.split("d")[1] + if "+" in ctx.message.content: + number_to_add = int(ctx.message.content.split("+")[-1]) + + await ctx.send(embed=dice.roll(number_of_die, sides, number_to_add)) + + @commands.command(name="excuse") + async def excuse(self, ctx: commands.Context): + import excuse + + await ctx.send(excuse.get_excuse()) + + @commands.command(name="ask") + async def ask(self, ctx: commands.Context): + import questions + + await ctx.send( + questions.answer_question(ctx.message.content), + ) + + @commands.command(name="meme") + async def meme(self, ctx: commands.Context): + + import meme_gen + + await ctx.message.delete() + await ctx.send( + embed=core_utils.generate_embed( + embed_url=meme_gen.parse_message(ctx.message.content) + ) + ) + + @commands.command(name="define", aliases=["ud"]) + async def define(self, ctx: commands.Context): + + import define_word + + await ctx.send(embed=define_word.get_definition(ctx.message.content)) + + @commands.command(name="wallpaper") + async def wallpaper(self, ctx: commands.Context): + import wallpaper + + async with ctx.message.channel.typing(): + await ctx.send( + embed=core_utils.generate_embed( + embed_url=wallpaper.get_wall(ctx.message.content) + ) + ) + + @commands.command(name="nft") + async def nft(self, ctx: commands.Context): + + import nft + + result = nft.get_nft() + + await ctx.send(result) + + @commands.command(name="8ball") + async def eight_ball(self, ctx: commands.Context): + + import eight_ball + + result = eight_ball.check_8ball(ctx.message.content) + + await ctx.send(":8ball: %s :8ball:" % result) + + @commands.command(name="flows") + async def flows(self, ctx: commands.Context): + import river_stats + + result = river_stats.get_stats() + await ctx.send(embed=result) + + +def setup(bot): + bot.add_cog(Cheeky(bot)) diff --git a/app/cogs/game_apis.py b/app/cogs/game_apis.py new file mode 100644 index 00000000..44aae44e --- /dev/null +++ b/app/cogs/game_apis.py @@ -0,0 +1,36 @@ +from discord.ext import commands +import core_utils +import discord + + +class Games(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="bf5") + async def bf5(self, ctx: commands.Context): + 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" + ) + + @commands.command(name="ffxiv") + async def ffxiv(self, ctx: commands.Context, first_name, last_name, server): + import ffxiv + + async with ctx.message.channel.typing(): + try: + name = "%s %s" % (first_name, last_name) + await ctx.send(embed=ffxiv.make_request(name=name, server=server)) + 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" + ) + + +def setup(bot): + bot.add_cog(Games(bot)) diff --git a/app/cogs/server_utils.py b/app/cogs/server_utils.py new file mode 100644 index 00000000..31173c63 --- /dev/null +++ b/app/cogs/server_utils.py @@ -0,0 +1,186 @@ +from discord.ext import commands +import os +import discord + + +class ServerUtils(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command() + async def ping(self, ctx: commands.Context): + await ctx.send("pong") + + @commands.command(name="invite") + async def invite(self, ctx: commands.Context): + # 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( + max_uses=1, + max_age=3600, + temporary=temp, + ) + await ctx.send("Check your DMs") + await ctx.author.send(invite) + + @commands.command(name="emoji") + async def emoji(self, ctx: commands.Context, url, emoji_name): + await ctx.message.delete() + 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 + + @commands.command() + async def timeout( + self, + ctx: commands.Context, + member: discord.Member = None, + time=None, + *, + reason=None, + ): + if not ctx.message.author.discriminator in ["2528", "4082"]: + return + + import humanfriendly + import datetime + + time = humanfriendly.parse_timespan(time) + await member.timeout( + until=discord.utils.utcnow() + datetime.timedelta(seconds=time) + ) + await member.send( + "You have been timed out for %s seconds for %s" % (time, reason) + ) + await ctx.send("Timed %s out for %s seconds" % (member.mention, time)) + + @commands.command(name="source") + async def source(self, ctx: commands.Context): + + await ctx.send("https://git.luker.gq/ldooks/dragon-bot") + + @commands.command(name=".") + async def roles(self, ctx: commands.Context): + 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 + + @commands.command(name="send") + async def send(self, ctx: commands.Context): + if ctx.message.author.discriminator == "2528": + await bot.get_channel(152921472304676865).send( + " ".join(ctx.message.content.split()[1:]) + ) + + @commands.command(name="info") + async def info(self, ctx: commands.Context): + 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 %s" % bot.user.name, + value="\n".join("[%s](%s)" % (x.name, x.jump_url) for x in bot.guilds), + ) + embed.set_thumbnail(url=server.icon) + + await ctx.send(embed=embed) + + @commands.command(name="purge") + async def purge(self, ctx: commands.Context, count=None): + def is_me(m): + return m.author == ctx.message.author + + num = 20 + if count: + num = int(count) + 1 + await ctx.message.channel.purge(limit=num, check=is_me) + + @commands.command(name="cleanup") + async def cleanup(self, ctx: commands.Context): + 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() + + @commands.command(name="shoo") + async def shoo(self, ctx: commands.Context): + if ctx.message.author.id != 144986109804412928: + return + await ctx.message.delete() + await ctx.message.guild.leave() + + @commands.command(name="help") + async def help(self, ctx: commands.Context, method): + + import help_methods + + if len(ctx.message.content.split()) > 1: + await ctx.send(help_methods.parse_message(method)) + else: + await ctx.send(embed=help_methods.get_help_embed(bot)) + + +def setup(bot): + bot.add_cog(ServerUtils(bot)) diff --git a/app/cogs/user_functions.py b/app/cogs/user_functions.py new file mode 100644 index 00000000..6cf40cda --- /dev/null +++ b/app/cogs/user_functions.py @@ -0,0 +1,23 @@ +from discord.ext import commands +import core_utils +import discord +import os + + +class Users(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="avatar") + async def avatar(self, ctx: commands.Context, user: discord.Member): + await ctx.send( + embed=core_utils.generate_embed( + embed_title="{}#{}".format(user.name, user.discriminator), + embed_url=user.avatar, + embed_description="[Direct Link]({})".format(user.avatar), + ) + ) + + +def setup(bot): + bot.add_cog(Users(bot)) diff --git a/app/cogs/weeb_shit.py b/app/cogs/weeb_shit.py new file mode 100644 index 00000000..9dfa302b --- /dev/null +++ b/app/cogs/weeb_shit.py @@ -0,0 +1,62 @@ +from discord.ext import commands +import get_from_reddit +import core_utils +import requests + + +class Weeb(commands.Cog): + def __init_(self, bot): + self.bot: commands.Bot = bot + + @commands.command(name="wink") + async def wink(self, ctx: commands.Context): + await ctx.send( + embed=core_utils.generate_embed( + embed_url=requests.get("https://some-random-api.ml/animu/wink").json()[ + "link" + ] + ) + ) + + @commands.command(name="smug") + async def smug(self, ctx: commands.Context): + + await ctx.send( + embed=core_utils.generate_embed( + embed_url=get_from_reddit.get_image("smuganimegirls") + ) + ) + + @commands.command(name="pout") + async def pout(self, ctx: commands.Context): + + await ctx.send( + embed=core_utils.generate_embed( + embed_url=get_from_reddit.get_image("pouts") + ) + ) + + @commands.command(name="owo") + async def owo(self, ctx: commands.Context): + from owotext import OwO + + uwu = OwO() + await ctx.send(uwu.whatsthis(" ".join(ctx.message.content.split()[1:]))) + + @commands.command(name="lewd") + async def lewd(self, ctx: commands.Context): + 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=core_utils.generate_embed( + embed_url=lewds.get_lewd(), + embed_title="{} is being lewd".format(ctx.message.author.name), + ) + ) + + +def setup(bot): + bot.add_cog(Weeb(bot)) diff --git a/app/core_utils.py b/app/core_utils.py index 8116420b..aeca3938 100755 --- a/app/core_utils.py +++ b/app/core_utils.py @@ -1,4 +1,5 @@ import requests +import discord def download_image(url, path=None): @@ -20,3 +21,36 @@ def download_image(url, path=None): open(path, "wb").write(requests.get(url).content) return path return "Invalid image format" + + +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 diff --git a/app/dice.py b/app/dice.py index 5c06f4f8..f8a166da 100755 --- a/app/dice.py +++ b/app/dice.py @@ -36,18 +36,3 @@ def roll(number_of_die, sides, number_to_add=None): name="**Total**", value=":game_die: %s" % sum(results), inline=False ) return embed - - -def parse_message(message): - message = " ".join(message.split()[1:]) - if "+" in message: - try: - number_to_add = int(message.split("+")[-1]) - return roll( - message.split("d")[0], - message.split("d")[1].split("+")[0], - number_to_add, - ) - except ValueError: - return "Could not add that number to the total roll" - return roll(message.split("d")[0], message.split("d")[1]) diff --git a/app/help_methods.py b/app/help_methods.py index 61f80c72..6a174898 100755 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -271,8 +271,7 @@ def get_help_embed(bot): return embed -def parse_message(message): - method = message.split()[1] +def parse_message(method): try: explanation = get_help_message(method) except KeyError: diff --git a/app/wallpaper.py b/app/wallpaper.py index 82686baf..6b64ab6b 100755 --- a/app/wallpaper.py +++ b/app/wallpaper.py @@ -36,20 +36,3 @@ def get_wall(message): return "Could not find an image for those tags." else: return response - - -def fcking_homepage(): - """ - fcking_homepage() - - Retrives the picture of the day from fuckinghomepage.com - """ - url = requests.get("http://fuckinghomepage.com") - soup = BeautifulSoup(url.content) - - for pic in soup.find_all("p"): - if "SWEET-ASS PICTURE" in "".join(pic.findAll(text=True)): - link = pic.find_next_sibling("p") - if "http://" or "https://" in link.get("href", ""): - link = link.find("small").find_next("a", href=True)["href"] - return urllib.parse.unquote(link.split("=")[1].split("&")[0]) diff --git a/helm/values.yaml b/helm/values.yaml index 2f01ba00..0e39869e 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -8,7 +8,7 @@ image: repository: ldooks/dragon-bot pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: "157" + tag: "158" imagePullSecrets: [] nameOverride: "" @@ -80,3 +80,4 @@ env: ffxiv_token: ffxiv_token gitlab_token: gitlab_token wolfram_token: wolfram_token + DRAGON_ENV: prod