diff --git a/main.py b/main.py index a8f8729..5fc275b 100644 --- a/main.py +++ b/main.py @@ -2,19 +2,19 @@ import os import random import util as u -from keep_alive import keep_alive +from keep_alive import keep_alive # as one might guess, this keeps the bot running import discord from dotenv import load_dotenv -# fancy tech stuff - gets the secrets +# fancy tech stuff - gets the secrets from the repl where it runs load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') # useful variables prefix = u.textRead("settings.txt")[3] client = discord.Client() -rps = False +rps = False # enables rock paper scissors game # displays when bot connects @client.event @@ -25,8 +25,11 @@ async def on_ready(): async def on_message(message): global rps + # makes sure the bot doesn't activate itself if message.author == client.user: return + + # rock paper scissors if message.content.startswith(prefix + "rps"): await message.channel.send("Ok let's play. You go first.") rps = True @@ -49,28 +52,33 @@ async def on_message(message): rps = False return + # pulls from a list of yo mama jokes if message.content.startswith(prefix + "insult"): insultRequest = message.content.split(" ") - if len(insultRequest) > 1 and insultRequest[1].startswith("<@"): - await message.channel.send(u.randomYourMomJoke(insultRequest[1])) + if len(insultRequest) > 2 and insultRequest[2].startswith("<@"): + await message.channel.send(u.randomYourMomJoke(insultRequest[2])) if random.randrange(100) > 100 - int(u.textRead("settings.txt")[2]): - await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 4))+ '.gif')) + await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 5))+ '.gif')) # chance to send a gif else: await message.channel.send(u.randomYourMomJoke()) if random.randrange(100) > 100 - int(u.textRead("settings.txt")[2]): - await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 4))+ '.gif')) + await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 5))+ '.gif')) # chance to send a gif return + + # randomly generated yo mama joke elif message.content.startswith(prefix + "geninsult"): insultRequest = message.content.split(" ") if len(insultRequest) > 1 and insultRequest[1].startswith("<@"): await message.channel.send(u.generateYourMomJoke(insultRequest[1])) if random.randrange(100) > 100 - int(u.textRead("settings.txt")[2]): - await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 4))+ '.gif')) + await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 5))+ '.gif')) else: await message.channel.send(u.generateYourMomJoke()) if random.randrange(100) > 100 - int(u.textRead("settings.txt")[2]): - await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 4))+ '.gif')) + await message.channel.send(file=discord.File('insults/roastedgifs/roasted'+str(random.randint(1, 5))+ '.gif')) return + + # explains the bot elif message.content.startswith(prefix + "help"): await message.channel.send(f""" Hello! I'm a very accurate representation of an annoying adolescent, created by a group of annoying adolescents. I tell the best your mom jokes you've ever encountered. Try some of these commands! @@ -95,17 +103,19 @@ async def on_message(message): Curse another Discord server with my presence! https://discord.com/api/oauth2/authorize?client_id=944652303632322591&permissions=277025459264&redirect_uri=https%3A%2F%2Fdiscord.com%2Fchannels%2F%40me&response_type=code&scope=bot%20messages.read -*I'm dedicated to ZA!* You know what you said about my mother. +*I'm dedicated to ZA! You know what you said about my mother.* *This is a submission for Hack Kean 2022* """) return + # responds to any animal mentions with a rude comparison to your mother animal = u.containsAny(message.content, u.textRead("insults/animals.txt")) if random.randrange(100) > 100 - int(u.textRead("settings.txt")[0]) and animal: await message.channel.send(f'{animal.title()}? Like your mom?') return + # random snarky comments if random.randrange(100) > 100 - int(u.textRead("settings.txt")[1]): if ( message.content.lower().startswith("who ") or @@ -133,4 +143,4 @@ async def on_message(message): return keep_alive() -client.run(TOKEN) \ No newline at end of file +client.run(TOKEN) diff --git a/settings.txt b/settings.txt index 6998449..3161aab 100644 --- a/settings.txt +++ b/settings.txt @@ -1,4 +1,4 @@ 100 -5 -100 -! \ No newline at end of file +10 +20 +ree! \ No newline at end of file diff --git a/todo.md b/todo.md deleted file mode 100644 index 59936ae..0000000 --- a/todo.md +++ /dev/null @@ -1,4 +0,0 @@ -help menu that includes: - - change the prefix(maybe) - - change frequency of animal responses - - change frequency of misc responses \ No newline at end of file diff --git a/util.py b/util.py index 4d98fa6..04f6648 100644 --- a/util.py +++ b/util.py @@ -1,11 +1,13 @@ import random +# checks messages def containsAny(searchIn, strings): searchIn = searchIn.lower() for i in strings: if i in searchIn: return i return None +# turns file into list def textRead(fname): with open(fname) as f: fList = f.readlines() @@ -13,6 +15,7 @@ def textRead(fname): fList[i] = fList[i].strip("\n") return fList +# selects random joke from list def randomYourMomJoke(victim=""): insultList = textRead("insults/yourMom.txt") @@ -21,15 +24,17 @@ def randomYourMomJoke(victim=""): else: return "Hey " + victim + ", " + random.choice(insultList) +# creates a random joke that usually makes no sense def generateYourMomJoke(victim=""): verb = random.choice(textRead("insults/verbs.txt")) noun = random.choice(textRead("insults/nouns.txt")) adj = random.choice(textRead("insults/adjectives.txt")) joke_format = random.choice(textRead("insults/jokeTemplates.txt")) + # creates joke from random template and random words insult = joke_format.format(verb = verb, noun = noun, adjective = adj) if victim == "": return insult else: - return "Hey " + victim + ", " + insult \ No newline at end of file + return "Hey " + victim + ", " + insult