📝 Commenting and formatting

This commit is contained in:
NikolajDanger
2020-07-29 10:38:37 +02:00
parent 94c6289cc1
commit ef434ecee8
12 changed files with 260 additions and 220 deletions

View File

@ -8,38 +8,28 @@ import string
import json
import random
import funcs
from funcs import *
funcs.makeFiles()
funcs.shuffle()
commandPrefix = "!"
# Gets secret bot token
with open("token.txt","r") as f:
token = f.read().replace("\n","")
# Blackjack shuffle variables
blackjackMinCards = 50
blackjackDecks = 4
client = discord.Client()
# Variable for reacting to messages
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
# Logs in
@client.event
async def on_ready():
funcs.logThis("Logged in as "+client.user.name+", "+str(client.user.id))
game = discord.Game("Some weeb shit")
await client.change_presence(activity=game)
# Reads messages and tests if they are Gwendolyn commands
@client.event
async def on_message(message):
# Sends the contents of "help.txt"
if message.content.lower().startswith("!help"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
if message.content.lower() == "!help" or message.content.lower() == "!help ":
async def parseCommands(message,content):
# Sends the contents of a help file, as specified by the message.
if content.startswith("help"):
if content == "help" or content == "help ":
with codecs.open("resources/help/help.txt",encoding="utf-8") as f:
text = f.read()
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
await message.channel.send(embed = em)
else:
command = message.content.lower().replace(" ","-").replace("!","")
funcs.logThis("Looking for "+command+".txt")
command = content.replace(" ","-")
logThis("Looking for "+command+".txt")
try:
with codecs.open("resources/help/"+command+".txt",encoding="utf-8") as f:
text = f.read()
@ -49,13 +39,12 @@ async def on_message(message):
await message.channel.send("Couldn't find help for that command")
# Logs whatever you write in the message
if message.content.lower().startswith("!log "):
funcs.logThis(message.content.lower().replace("!log ",""))
if content.startswith("log "):
logThis(content.replace("log ",""))
# Stops the bot
elif message.content.lower().startswith("!stop"):
elif content.startswith("stop"):
if message.author.display_name == "Nikolaj":
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
await message.channel.send("Logging out...")
with open("resources/games/games.json","r") as f:
@ -70,31 +59,28 @@ async def on_message(message):
await client.logout()
else:
funcs.logThis(message.author.display_name+" tried to run "+message.content)
logThis(message.author.display_name+" tried to run stop me!")
await message.channel.send("I don't think I will, "+message.author.display_name)
# Does a hello with the helloFunc function from funcs/gwendolynFuncs.py
elif message.content.lower().startswith("!hello"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
await message.channel.send(funcs.helloFunc(message.author.display_name))
# Does a hello with the helloFunc function from funcs/gwendolynpy
elif content.startswith("hello"):
await message.channel.send(helloFunc(message.author.display_name))
# Rolls dice with the roll_dice function from funcs/roll/dice.py
elif message.content.lower().startswith("!roll"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
if message.content.lower() == "!roll" or message.content.lower() == "!roll ":
await message.channel.send(funcs.roll_dice(message.author.display_name))
elif content.startswith("roll"):
if content == "roll" or content == "roll ":
await message.channel.send(roll_dice(message.author.display_name))
else:
await message.channel.send(funcs.roll_dice(message.author.display_name, message.content.lower().replace("!roll","")))
await message.channel.send(roll_dice(message.author.display_name, content.replace("roll","")))
# Looks up a spell with the spellFunc function from funcs/lookup/lookupFuncs.py
elif message.content.lower().startswith("!spell "):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
await message.channel.send(funcs.spellFunc(message.content))
# Looks up a spell with the spellFunc function from funcs/lookup/lookuppy
elif content.startswith("spell "):
await message.channel.send(spellFunc(cap(content.replace("spell",""))))
# Looks up a monster with the monsterFuncs() from funcs/lookup/lookupFuncs.py
elif message.content.lower().startswith("!monster "):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
title, text1, text2, text3, text4, text5 = funcs.monsterFunc(message.content)
# Looks up a monster with the monsterFuncs() from funcs/lookup/lookuppy
elif content.startswith("monster "):
title, text1, text2, text3, text4, text5 = monsterFunc(cap(content.replace("monster","")))
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
# Sends the received information. Seperates into seperate messages if
@ -138,22 +124,19 @@ async def on_message(message):
await message.channel.send(embed = em5_2)
# Sends an image of the Senkulpa map
elif message.content.lower().startswith("!map"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
elif content.startswith("map"):
await message.channel.send("https://i.imgur.com/diMXXJs.jpg")
# Finds a random image on the internet with the imageFuncs function from
# funcs/gwendolynFuncs.py
elif message.content.lower().startswith("!image"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
await message.channel.send(funcs.imageFunc())
# funcs/gwendolynpy
elif content.startswith("image"):
await message.channel.send(imageFunc())
# Sends information about a random movie with the movieFunc function from
# funcs/other/movie.py
elif message.content.lower().startswith("!movie"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
elif content.startswith("movie"):
async with message.channel.typing():
title, plot, cover, cast = funcs.movieFunc()
title, plot, cover, cast = movieFunc()
if title == "error":
await message.channel.send("An error occurred. Try again")
else:
@ -163,50 +146,44 @@ async def on_message(message):
await message.channel.send(embed = embed)
# Generates a random name with the nameGen function from funcs/other/generators.py
elif message.content.lower().startswith("!name"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
await message.channel.send(funcs.nameGen())
elif content.startswith("name"):
await message.channel.send(nameGen())
# Generates a random tavern name with the tavernGen function from funcs/other/generators.py
elif message.content.lower().startswith("!tavern"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
await message.channel.send(funcs.tavernGen())
elif content.startswith("tavern"):
await message.channel.send(tavernGen())
# Changes the "Playing this game" thing in Discord
elif message.content.lower().startswith("!game "):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
gamePlaying = funcs.cap(message.content.lower().replace("!game ",""))
elif content.startswith("game "):
gamePlaying = cap(content.replace("game ",""))
game = discord.Game(gamePlaying)
await client.change_presence(activity=game)
# Rolls star wars dice with the parseRoll function from funcs/swfuncs/swroll.py
elif message.content.lower().startswith("!swroll"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
command = funcs.cap(message.content.lower().replace("!swroll",""))
newMessage = funcs.parseRoll(message.author.display_name,command)
elif content.startswith("swroll"):
command = cap(content.replace("swroll",""))
newMessage = parseRoll(message.author.display_name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
# Deals with Destiny Points and stuff
elif message.content.lower().startswith("!swd"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
command = message.content.lower().replace("!swd","")
newMessage = funcs.parseDestiny(message.author.display_name,command)
elif content.startswith("swd"):
command = content.replace("swd","")
newMessage = parseDestiny(message.author.display_name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
# Rolls for critical injuries
elif message.content.lower().startswith("!swcrit"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
command = message.content.lower().replace("!swcrit","").replace(" ","").replace("+","")
elif content.startswith("swcrit"):
command = content.replace("swcrit","").replace(" ","").replace("+","")
if command == "":
command = 0
try:
newMessage = funcs.critRoll(int(command))
newMessage = critRoll(int(command))
except:
newMessage = "Try using a number, stupid"
@ -216,10 +193,9 @@ async def on_message(message):
# Accesses and changes character sheet data with the parseChar function
# from funcs/swfuncs/swchar.py
elif message.content.lower().startswith("!swchar") or message.content.lower().startswith("!sw"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
command = string.capwords(message.content.lower().replace("!swchar","").replace("!sw","").replace("+","+ ").replace("-","- ").replace(",",", "))
title, desc = funcs.parseChar(message.author.display_name,command)
elif content.startswith("swchar") or content.startswith("sw"):
command = string.capwords(content.replace("swchar","").replace("sw","").replace("+","+ ").replace("-","- ").replace(",",", "))
title, desc = parseChar(message.author.display_name,command)
if title != "":
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
await message.channel.send(embed = em1)
@ -228,13 +204,12 @@ async def on_message(message):
# Searches for a specific page on the Senkulpa Wiki
elif message.content.lower().startswith("!wiki "):
elif content.startswith("wiki "):
async with message.channel.typing():
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
command = string.capwords(message.content.lower().replace("!wiki ",""))
title, content, thumbnail = funcs.findWikiPage(command)
command = string.capwords(content.replace("wiki ",""))
title, content, thumbnail = findWikiPage(command)
if title != "":
funcs.logThis("Sending the embedded message")
logThis("Sending the embedded message")
content += "\n[Læs mere](https://senkulpa.fandom.com/da/wiki/"+title.replace(" ","_")+")"
embed = discord.Embed(title = title, description = content, colour=0xDEADBF)
if thumbnail != "":
@ -246,10 +221,9 @@ async def on_message(message):
# Runs a trivia game
elif message.content.lower().startswith("!trivia"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
if message.content.lower() == "!trivia" or message.content.lower() == "!trivia ":
question, answers, correctAnswer = funcs.triviaStart(str(message.channel))
elif content.startswith("trivia"):
if content == "trivia" or content == "trivia ":
question, answers, correctAnswer = triviaStart(str(message.channel))
if answers != "":
results = "**"+question+"**\n"
for answer in range(len(answers)):
@ -259,7 +233,7 @@ async def on_message(message):
await asyncio.sleep(60)
funcs.triviaCountPoints(str(message.channel))
triviaCountPoints(str(message.channel))
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -268,64 +242,65 @@ async def on_message(message):
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
funcs.logThis("Time's up for the trivia question in "+str(message.channel))
await message.channel.send("Time's up! The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
logThis("Time's up for the trivia question in "+str(message.channel))
await message.channel.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
else:
await message.channel.send(question)
elif message.content.lower().startswith("!trivia "):
command = message.content.lower().replace("!trivia ","")
response = funcs.triviaOtherThing(message.author.display_name.lower(),str(message.channel),command)
elif content.startswith("trivia "):
command = content.replace("trivia ","")
response = triviaAnswer(message.author.display_name.lower(),str(message.channel),command)
if response.startswith("Locked in "):
await message.add_reaction("👍")
else:
await message.channel.send(response)
else:
funcs.logThis("I didn't understand that")
logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
#Checks your GwendoBucks balance
elif message.content.lower().startswith("!balance"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
response = funcs.checkBalance(message.author.display_name.lower())
# Checks your GwendoBucks balance
elif content.startswith("balance"):
response = checkBalance(message.author.display_name.lower())
if response == 1:
new_message = message.author.display_name + " has " + str(response) + " GwendoBuck"
else:
new_message = message.author.display_name + " has " + str(response) + " GwendoBucks"
await message.channel.send(new_message)
#gives money to other player
elif message.content.lower().startswith("!give "):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
commands = message.content.lower().split(" ")
# Gives money to other player
elif content.startswith("give "):
commands = content.split(" ")
if len(commands) >= 3:
try:
amount = int(commands[2])
response = funcs.giveMoney(message.author.display_name.lower(),commands[1],amount)
response = giveMoney(message.author.display_name.lower(),commands[1],amount)
await message.channel.send(response)
except:
funcs.logThis("I didn't quite understand that")
logThis("I didn't quite understand that")
await message.channel.send("I didn't quite understand that")
else:
funcs.logThis("I didn't understand that")
logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
elif message.content.lower().startswith("!blackjack"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
if message.content.lower() == "!blackjack" or message.content.lower() == "!blackjack ":
new_message = funcs.blackjackStart(str(message.channel))
# Runs a game of Blackjack
elif content.startswith("blackjack"):
# Starts the game
if content == "blackjack" or content == "blackjack ":
new_message = blackjackStart(str(message.channel))
if new_message == "started":
cardsLeft = 0
with open("resources/games/blackjackCards.txt","r") as f:
for line in f:
cardsLeft += 1
if cardsLeft < 50:
funcs.shuffle()
# Shuffles if not enough cards
if cardsLeft < blackjackMinCards:
blackjackShuffle(blackjackDecks)
logThis("Shuffling the blackjack deck...")
await message.channel.send("Shuffling the deck...")
new_message = "Blackjack game started. Use \"!blackjack bet [amount]\" to enter the game within the next 30 seconds."
new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds."
await message.channel.send(new_message)
old_image = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png"))
@ -339,8 +314,9 @@ async def on_message(message):
gamedone = True
await message.channel.send("No one entered the game. Ending the game.")
# Loop of game rounds
while gamedone == False:
new_message, allStanding, gamedone = funcs.blackjackContinue(str(message.channel))
new_message, allStanding, gamedone = blackjackContinue(str(message.channel))
if new_message != "":
await message.channel.send(new_message)
if gamedone == False:
@ -351,82 +327,109 @@ async def on_message(message):
else:
await asyncio.sleep(30)
new_message = funcs.blackjackFinish(str(message.channel))
new_message = blackjackFinish(str(message.channel))
await message.channel.send(new_message)
else:
await message.channel.send(new_message)
elif message.content.lower().startswith("!blackjack bet"):
commands = message.content.lower().split(" ")
# Entering game and placing bet
elif content.startswith("blackjack bet"):
commands = content.split(" ")
try:
amount = int(commands[2])
except:
funcs.logThis("I didn't understand that")
logThis("I didn't understand that")
response = "I didn't understand that"
else:
response = funcs.blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount)
response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount)
await message.channel.send(response)
elif message.content.lower().startswith("!blackjack hit"):
if message.content.lower() == "!blackjack hit" or message.content.lower() == "!blackjack hit ":
response = funcs.blackjackHit(str(message.channel),message.author.display_name)
# Hitting
elif content.startswith("blackjack hit"):
if content == "blackjack hit" or content == "blackjack hit ":
response = blackjackHit(str(message.channel),message.author.display_name)
else:
commands = message.content.lower().split(" ")
commands = content.split(" ")
try:
handNumber = int(commands[2])
except:
handNumber = 0
response = funcs.blackjackHit(str(message.channel),message.author.display_name,handNumber)
response = blackjackHit(str(message.channel),message.author.display_name,handNumber)
if response == "accept":
await message.add_reaction("👍")
else:
await message.channel.send(response)
elif message.content.lower().startswith("!blackjack stand"):
response = funcs.blackjackStand(str(message.channel),message.author.display_name,0)
# Standing
elif content.startswith("blackjack stand"):
response = blackjackStand(str(message.channel),message.author.display_name,0)
if response == "accept":
await message.add_reaction("👍")
else:
await message.channel.send(response)
elif message.content.lower().startswith("!blackjack double"):
if message.content.lower() == "!blackjack hit" or message.content.lower() == "!blackjack hit ":
response = funcs.blackjackDouble(str(message.channel),message.author.display_name)
# Doubling bet
elif content.startswith("blackjack double"):
if content == "blackjack hit" or content == "blackjack hit ":
response = blackjackDouble(str(message.channel),message.author.display_name)
else:
commands = message.content.lower().split(" ")
commands = content.split(" ")
try:
handNumber = int(commands[2])
except:
handNumber = 0
response = funcs.blackjackDouble(str(message.channel),message.author.display_name,handNumber)
response = blackjackDouble(str(message.channel),message.author.display_name,handNumber)
await message.channel.send(response)
elif message.content.lower().startswith("!blackjack split"):
response = funcs.blackjackSplit(str(message.channel),message.author.display_name)
# Splitting hand
elif content.startswith("blackjack split"):
response = blackjackSplit(str(message.channel),message.author.display_name)
await message.channel.send(response)
else:
await message.channel.send("I didn't quite understand that")
elif message.content.lower().startswith("!fourinarow"):
funcs.logThis(message.author.display_name+" ran \""+message.content+"\"")
response, showImage = funcs.decipherCommand(message.content.lower().replace("!fourinarow",""),str(message.channel),message.author.display_name)
# Runs a game of four in a row
elif content.startswith("fourinarow"):
response, showImage = parseFourInARow(content.replace("fourinarow",""),str(message.channel),message.author.display_name)
await message.channel.send(response)
funcs.logThis(response)
logThis(response)
if showImage:
await message.channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(message.channel)+".png"))
# Makes files if they don't exist yet
makeFiles()
# Shuffling cards
blackjackShuffle(4)
# Gets secret bot token
with open("token.txt","r") as f:
token = f.read().replace("\n","")
client = discord.Client()
# Logs in
@client.event
async def on_ready():
logThis("Logged in as "+client.user.name+", "+str(client.user.id))
game = discord.Game("Some weeb shit")
await client.change_presence(activity=game)
# Reads messages and tests if they are Gwendolyn commands
@client.event
async def on_message(message):
content = message.content
if content.startswith(commandPrefix):
logThis(message.author.display_name+" ran \""+content+"\"")
await parseCommands(message,content.lower()[1:])
# Is a bit sassy sometimes
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
if ("gwendolyn" in message.content.lower() or message.content.startswith("!")) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower():
funcs.logThis(message.author.display_name+" was a bit mean")
if ("gwendolyn" in message.content.lower() or message.content.startswith(commandPrefix)) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower():
logThis(message.author.display_name+" was a bit mean")
emoji = random.choice(["😠", "🖕", "👎"])
await message.add_reaction(emoji)