Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -133,4 +143,4 @@ async def on_message(message):
return

keep_alive()
client.run(TOKEN)
client.run(TOKEN)
6 changes: 3 additions & 3 deletions settings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
100
5
100
!
10
20
ree!
4 changes: 0 additions & 4 deletions todo.md

This file was deleted.

7 changes: 6 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
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()
for i in range(len(fList)):
fList[i] = fList[i].strip("\n")
return fList

# selects random joke from list
def randomYourMomJoke(victim=""):
insultList = textRead("insults/yourMom.txt")

Expand All @@ -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
return "Hey " + victim + ", " + insult