🐛 Fixed clear reactions bug

Gwendolyn used to throw an error when trying to remove messages from
DMs. Now she just doesn't try :thumbs-up:
This commit is contained in:
NikolajDanger
2021-04-12 15:37:34 +02:00
parent 78d8575e15
commit 648308831d
2 changed files with 40 additions and 9 deletions

View File

@ -61,11 +61,18 @@ class BedreNetflix():
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
async def addMovie(self, message, imdbId):
async def addMovie(self, message, imdbId, editMessage = True):
if imdbId == None:
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:
self.bot.log("Trying to add movie "+str(imdbId))
apiKey = self.bot.credentials.radarrKey
@ -81,13 +88,23 @@ class BedreNetflix():
r = requests.post(url= self.radarrURL+"movie?apikey="+apiKey,json = postData)
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")
elif r.status_code == 400:
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:
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)
#Returns a list of no more than 5 options when user requests a show
@ -140,6 +157,10 @@ class BedreNetflix():
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
async def addShow(self, message, imdbName):
if imdbName == None:

View File

@ -50,16 +50,26 @@ class EventHandler():
imdbID = None
else:
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:
showPick = emojiToCommand(reaction.emoji)
if showPick == "none":
imdbName = None
else:
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}"):
self.bot.log("They reacted to the hangman message")