🔀 General bug fixing

General bug fixing
This commit is contained in:
NikolajDanger
2021-04-12 15:40:21 +02:00
committed by GitHub
15 changed files with 76 additions and 72 deletions

View File

@ -50,6 +50,12 @@ class Gwendolyn(commands.Bot):
self.log(f"{ctx.author.display_name} tried to stop me! (error code 201)",str(ctx.channel_id)) self.log(f"{ctx.author.display_name} tried to stop me! (error code 201)",str(ctx.channel_id))
await ctx.send(f"I don't think I will, {ctx.author.display_name} (error code 201)") await ctx.send(f"I don't think I will, {ctx.author.display_name} (error code 201)")
async def defer(self, ctx):
try:
await ctx.defer()
except:
self.log("defer failed")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -2,7 +2,7 @@ import discord, codecs, string, json
from discord.ext import commands from discord.ext import commands
from discord_slash import cog_ext from discord_slash import cog_ext
from utils import getParams from utils import getParams # pylint: disable=import-error
params = getParams() params = getParams()

View File

@ -172,10 +172,7 @@ class Blackjack():
# When players try to hit # When players try to hit
async def hit(self, ctx, handNumber = 0): async def hit(self, ctx, handNumber = 0):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
roundDone = False roundDone = False
@ -239,10 +236,7 @@ class Blackjack():
# When players try to double down # When players try to double down
async def double(self, ctx, handNumber = 0): async def double(self, ctx, handNumber = 0):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
roundDone = False roundDone = False
@ -317,10 +311,7 @@ class Blackjack():
# When players try to stand # When players try to stand
async def stand(self, ctx, handNumber = 0): async def stand(self, ctx, handNumber = 0):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
roundDone = False roundDone = False
@ -378,10 +369,7 @@ class Blackjack():
# When players try to split # When players try to split
async def split(self, ctx, handNumber = 0): async def split(self, ctx, handNumber = 0):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
roundDone = False roundDone = False
@ -506,10 +494,7 @@ class Blackjack():
# Player enters the game and draws a hand # Player enters the game and draws a hand
async def playerDrawHand(self, ctx, bet : int): async def playerDrawHand(self, ctx, bet : int):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
collection = self.bot.database["blackjack games"] collection = self.bot.database["blackjack games"]
@ -565,10 +550,7 @@ class Blackjack():
# Starts a game of blackjack # Starts a game of blackjack
async def start(self, ctx): async def start(self, ctx):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
blackjackMinCards = 50 blackjackMinCards = 50
blackjackDecks = 4 blackjackDecks = 4

View File

@ -26,10 +26,7 @@ class ConnectFour():
# Starts the game # Starts the game
async def start(self, ctx, opponent): async def start(self, ctx, opponent):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
game = self.bot.database["connect 4 games"].find_one({"_id":channel}) game = self.bot.database["connect 4 games"].find_one({"_id":channel})
@ -228,10 +225,7 @@ class ConnectFour():
# Parses command # Parses command
async def surrender(self, ctx): async def surrender(self, ctx):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
game = self.bot.database["connect 4 games"].find_one({"_id":channel}) game = self.bot.database["connect 4 games"].find_one({"_id":channel})

View File

@ -10,7 +10,7 @@ class Hangman():
self.draw = DrawHangman(bot) self.draw = DrawHangman(bot)
async def start(self, ctx): async def start(self, ctx):
await ctx.defer() await self.bot.defer(ctx)
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
game = self.bot.database["hangman games"].find_one({"_id":channel}) game = self.bot.database["hangman games"].find_one({"_id":channel})

View File

@ -93,10 +93,7 @@ class HexGame():
# Starts the game # Starts the game
async def start(self, ctx, opponent): async def start(self, ctx, opponent):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
channel = str(ctx.channel_id) channel = str(ctx.channel_id)
game = self.bot.database["hex games"].find_one({"_id":channel}) game = self.bot.database["hex games"].find_one({"_id":channel})

View File

@ -106,10 +106,7 @@ class Invest():
return "no" return "no"
async def parseInvest(self, ctx, parameters): async def parseInvest(self, ctx, parameters):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
user = f"#{ctx.author.id}" user = f"#{ctx.author.id}"
if parameters.startswith("check"): if parameters.startswith("check"):

View File

@ -15,7 +15,7 @@ class Money():
else: return 0 else: return 0
async def sendBalance(self, ctx): async def sendBalance(self, ctx):
await ctx.defer() await self.bot.defer(ctx)
response = self.checkBalance("#"+str(ctx.author.id)) response = self.checkBalance("#"+str(ctx.author.id))
if response == 1: if response == 1:
new_message = ctx.author.display_name + " has " + str(response) + " GwendoBuck" new_message = ctx.author.display_name + " has " + str(response) + " GwendoBuck"
@ -36,10 +36,7 @@ class Money():
# Transfers money from one user to another # Transfers money from one user to another
async def giveMoney(self, ctx, user, amount): async def giveMoney(self, ctx, user, amount):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("Defer failed")
username = user.display_name username = user.display_name
if self.bot.databaseFuncs.getID(username) == None: if self.bot.databaseFuncs.getID(username) == None:
async for member in ctx.guild.fetch_members(limit=None): async for member in ctx.guild.fetch_members(limit=None):

View File

@ -86,10 +86,7 @@ class Trivia():
return None return None
async def triviaParse(self, ctx, answer): async def triviaParse(self, ctx, answer):
try: await self.bot.defer(ctx)
await ctx.defer()
except:
self.bot.log("defer failed")
if answer == "": if answer == "":
question, options, correctAnswer = self.triviaStart(str(ctx.channel_id)) question, options, correctAnswer = self.triviaStart(str(ctx.channel_id))
if options != "": if options != "":

View File

@ -13,7 +13,7 @@ class BedreNetflix():
#Returns a list of no more than 5 options when user requests a movie #Returns a list of no more than 5 options when user requests a movie
async def requestMovie(self, ctx, movieName): async def requestMovie(self, ctx, movieName):
await ctx.defer() await self.bot.defer(ctx)
self.bot.log("Searching for "+movieName) self.bot.log("Searching for "+movieName)
movieList = imdb.IMDb().search_movie(movieName) movieList = imdb.IMDb().search_movie(movieName)
@ -61,11 +61,18 @@ class BedreNetflix():
await message.add_reaction("") await message.add_reaction("")
message = await ctx.channel.fetch_message(message.id)
if message.content != "" and not isinstance(ctx.channel, discord.DMChannel):
await message.clear_reactions()
#Adds the requested movie to Bedre Netflix #Adds the requested movie to Bedre Netflix
async def addMovie(self, message, imdbId): async def addMovie(self, message, imdbId, editMessage = True):
if imdbId == None: if imdbId == None:
self.bot.log("Did not find what the user was searching for") self.bot.log("Did not find what the user was searching for")
await message.edit(embed = None, content = "Try searching for the IMDB id") if editMessage:
await message.edit(embed = None, content = "Try searching for the IMDB id")
else:
await message.channel.send("Try searching for the IMDB id")
else: else:
self.bot.log("Trying to add movie "+str(imdbId)) self.bot.log("Trying to add movie "+str(imdbId))
apiKey = self.bot.credentials.radarrKey apiKey = self.bot.credentials.radarrKey
@ -81,18 +88,28 @@ class BedreNetflix():
r = requests.post(url= self.radarrURL+"movie?apikey="+apiKey,json = postData) r = requests.post(url= self.radarrURL+"movie?apikey="+apiKey,json = postData)
if r.status_code == 201: if r.status_code == 201:
await message.edit(embed = None, content = postData["title"]+" successfully added to Bedre Netflix") if editMessage:
await message.edit(embed = None, content = postData["title"]+" successfully added to Bedre Netflix")
else:
await message.channel.send(postData["title"]+" successfully added to Bedre Netflix")
self.bot.log("Added "+postData["title"]+" to Bedre Netflix") self.bot.log("Added "+postData["title"]+" to Bedre Netflix")
elif r.status_code == 400: elif r.status_code == 400:
text = f"{postData['title']} is either already on Bedre Netflix, downloading, or not available" text = f"{postData['title']} is either already on Bedre Netflix, downloading, or not available"
await message.edit(embed = None, content = text) if editMessage:
await message.edit(embed = None, content = text)
else:
await message.channel.send(text)
else: else:
await message.edit(embed = None, content = "Something went wrong") if editMessage:
await message.edit(embed = None, content = "Something went wrong")
else:
await message.channel.send("Something went wrong")
self.bot.log(str(r.status_code)+" "+r.reason) self.bot.log(str(r.status_code)+" "+r.reason)
#Returns a list of no more than 5 options when user requests a show #Returns a list of no more than 5 options when user requests a show
async def requestShow(self, ctx, showName): async def requestShow(self, ctx, showName):
await ctx.defer() await self.bot.defer(ctx)
self.bot.log("Searching for "+showName) self.bot.log("Searching for "+showName)
movies = imdb.IMDb().search_movie(showName) #Replace with tvdb movies = imdb.IMDb().search_movie(showName) #Replace with tvdb
@ -140,6 +157,10 @@ class BedreNetflix():
await message.add_reaction("") await message.add_reaction("")
message = await ctx.channel.fetch_message(message.id)
if message.content != "" and not isinstance(ctx.channel, discord.DMChannel):
await message.clear_reactions()
#Adds the requested show to Bedre Netflix #Adds the requested show to Bedre Netflix
async def addShow(self, message, imdbName): async def addShow(self, message, imdbName):
if imdbName == None: if imdbName == None:
@ -307,7 +328,7 @@ class BedreNetflix():
await ctx.send("```"+messageText[:cutOffIndex]+"```") await ctx.send("```"+messageText[:cutOffIndex]+"```")
await SendLongMessage(ctx,messageText[cutOffIndex+1:]) await SendLongMessage(ctx,messageText[cutOffIndex+1:])
await ctx.defer() await self.bot.defer(ctx)
# showDM, showMovies, showShows, episodes # showDM, showMovies, showShows, episodes
params = [False, False, False, False] params = [False, False, False, False]

View File

@ -1,4 +1,4 @@
import discord, wolframalpha, requests, os import discord, discord_slash, wolframalpha, requests, os
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
class NerdShit(): class NerdShit():
@ -7,8 +7,8 @@ class NerdShit():
self.bot = bot self.bot = bot
async def wolfSearch(self,ctx,content): async def wolfSearch(self,ctx,content):
await self.bot.defer(ctx)
fnt = ImageFont.truetype('resources/fonts/times-new-roman.ttf', 20) fnt = ImageFont.truetype('resources/fonts/times-new-roman.ttf', 20)
await ctx.defer()
self.bot.log("Requesting data") self.bot.log("Requesting data")
bot = wolframalpha.Client(self.bot.credentials.wolfKey) bot = wolframalpha.Client(self.bot.credentials.wolfKey)
res = bot.query(content) res = bot.query(content)
@ -36,19 +36,19 @@ class NerdShit():
heights = [] heights = []
for count, pod in enumerate(chunk): for count, pod in enumerate(chunk):
heights += [height] heights += [height]
width = max(width,int(list(pod.img)[0]["@width"])) width = max(width,int(pod.img['@width']))
if titleChucks[x][count] == "": if titleChucks[x][count] == "":
placeForText = 0 placeForText = 0
else: else:
placeForText = 30 placeForText = 30
height += int(list(pod.img)[0]["@height"]) + 10 + placeForText height += int(pod.img["@height"]) + 10 + placeForText
width += 10 width += 10
height += 5 height += 5
wolfImage = Image.new("RGB",(width,height),color=(255,255,255)) wolfImage = Image.new("RGB",(width,height),color=(255,255,255))
for count, pod in enumerate(chunk): for count, pod in enumerate(chunk):
response = requests.get(list(pod.img)[0]["@src"]) response = requests.get(pod.img["@src"])
file = open("resources/wolfTemp.png", "wb") file = open("resources/wolfTemp.png", "wb")
file.write(response.content) file.write(response.content)
file.close() file.close()

View File

@ -34,7 +34,7 @@ class Other():
# Picks a random movie and returns information about it # Picks a random movie and returns information about it
async def movieFunc(self, ctx): async def movieFunc(self, ctx):
await ctx.defer() await self.bot.defer(ctx)
self.bot.log("Creating IMDb object") self.bot.log("Creating IMDb object")
imdbClient = imdb.IMDb() imdbClient = imdb.IMDb()
@ -138,7 +138,7 @@ class Other():
# Finds a page from the Senkulpa Wikia # Finds a page from the Senkulpa Wikia
async def findWikiPage(self, ctx, search : str): async def findWikiPage(self, ctx, search : str):
await ctx.defer() await self.bot.defer(ctx)
foundPage = False foundPage = False
if search != "": if search != "":

View File

@ -11,7 +11,7 @@ d20==1.1.0
discord-py-slash-command==1.1.1 discord-py-slash-command==1.1.1
discord.py==1.7.1 discord.py==1.7.1
dnspython==2.1.0 dnspython==2.1.0
docutils==0.17 docutils==0.16
fandom-py==0.2.1 fandom-py==0.2.1
finnhub-python==2.4.0 finnhub-python==2.4.0
gitdb==4.0.7 gitdb==4.0.7
@ -21,7 +21,7 @@ idna==2.10
IMDbPY==2020.9.25 IMDbPY==2020.9.25
isort==5.8.0 isort==5.8.0
jaraco.context==4.0.0 jaraco.context==4.0.0
lark-parser==0.11.2 lark-parser==0.9.0
lazy-object-proxy==1.6.0 lazy-object-proxy==1.6.0
lxml==4.6.3 lxml==4.6.3
mccabe==0.6.1 mccabe==0.6.1

View File

@ -50,16 +50,26 @@ class EventHandler():
imdbID = None imdbID = None
else: else:
imdbID = imdbIds[moviePick-1] imdbID = imdbIds[moviePick-1]
await message.clear_reactions()
await self.bot.other.bedreNetflix.addMovie(message, imdbID) if isinstance(channel, discord.DMChannel):
await message.delete()
await self.bot.other.bedreNetflix.addMovie(message, imdbID, False)
else:
await message.clear_reactions()
await self.bot.other.bedreNetflix.addMovie(message, imdbID)
elif bedreNetflixMessage and not addMovie: elif bedreNetflixMessage and not addMovie:
showPick = emojiToCommand(reaction.emoji) showPick = emojiToCommand(reaction.emoji)
if showPick == "none": if showPick == "none":
imdbName = None imdbName = None
else: else:
imdbName = imdbIds[showPick-1] imdbName = imdbIds[showPick-1]
await message.clear_reactions()
await self.bot.other.bedreNetflix.addShow(message, imdbName) if isinstance(channel, discord.DMChannel):
await message.delete()
await self.bot.other.bedreNetflix.addShow(message, imdbName, False)
else:
await message.clear_reactions()
await self.bot.other.bedreNetflix.addShow(message, imdbName)
elif self.bot.databaseFuncs.hangmanReactionTest(channel, message, f"#{user.id}"): elif self.bot.databaseFuncs.hangmanReactionTest(channel, message, f"#{user.id}"):
self.bot.log("They reacted to the hangman message") self.bot.log("They reacted to the hangman message")

View File

@ -2,6 +2,7 @@ import json
import logging import logging
import os import os
import sys import sys
import imdb
from .helperClasses import Options from .helperClasses import Options
FORMAT = " %(asctime)s | %(name)-16s | %(levelname)-8s | %(message)s" FORMAT = " %(asctime)s | %(name)-16s | %(levelname)-8s | %(message)s"
@ -17,6 +18,8 @@ handler.setFormatter(logging.Formatter(fmt = PRINTFORMAT, datefmt=DATEFORMAT))
printer.addHandler(handler) printer.addHandler(handler)
printer.propagate = False printer.propagate = False
imdb._logging.setLevel("CRITICAL")
def getParams(): def getParams():
with open("resources/slashParameters.json", "r") as f: with open("resources/slashParameters.json", "r") as f:
params = json.load(f) params = json.load(f)