diff --git a/.gitignore b/.gitignore index 11e9436..4264cef 100644 --- a/.gitignore +++ b/.gitignore @@ -153,6 +153,7 @@ token.txt credentials.txt options.txt resources/starWars/destinyPoints.txt +resources/bedreNetflix/ resources/games/hilo/ resources/games/blackjackTables/ resources/games/oldImages/ diff --git a/Gwendolyn.py b/Gwendolyn.py index dfb1669..b7a8ea5 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -2,7 +2,7 @@ import discord, os, finnhub from discord.ext import commands from pymongo import MongoClient -from funcs import logThis, makeFiles, Money, Funcs, SwChar, SwDestiny, SwRoll, Games, Generators +from funcs import logThis, makeFiles, Money, Funcs, SwChar, SwDestiny, SwRoll, Games, Generators, BedreNetflix commandPrefix = "!" @@ -17,6 +17,7 @@ class Credentials(): self.mongoDBUser = data[3][13:].replace(" ","") self.mongoDBPassword = data[4][17:].replace(" ","") self.wolfKey = data[5][19:].replace(" ","") + self.radarrKey = data[6][15:].replace(" ","") class Options(): def __init__(self): @@ -44,6 +45,7 @@ class Gwendolyn(commands.Bot): self.swdestiny = SwDestiny(self) self.generator = Generators() + self.bedreNetflix = BedreNetflix(self) Games(self) diff --git a/cogs/MiscCog.py b/cogs/MiscCog.py index e9d5120..404d3d8 100644 --- a/cogs/MiscCog.py +++ b/cogs/MiscCog.py @@ -11,6 +11,7 @@ class MiscCog(commands.Cog): self.client = client self.client.remove_command("help") self.generator = client.generator + self.bedreNetflix = client.bedreNetflix @commands.command(name = "help") async def helpCommand(self, ctx, *, content = ""): @@ -120,6 +121,11 @@ class MiscCog(commands.Cog): else: await ctx.send(content) + #Searches for movie and adds it to Bedre Netflix + @commands.command(aliases = ["rm","addmovie"]) + async def requestmovie(self, ctx, *, content): + await self.bedreNetflix.requestMovie(ctx,content) + #Looks up on Wolfram Alpha @commands.command() async def wolf(self, ctx, *, content): diff --git a/cogs/ReactionCog.py b/cogs/ReactionCog.py index f70660b..2e3dcc2 100644 --- a/cogs/ReactionCog.py +++ b/cogs/ReactionCog.py @@ -18,9 +18,19 @@ class ReactionCog(commands.Cog): except: fourInARowTheirTurn = False + addMovieMessage, imdbIds = self.client.funcs.addMovieReactionTest(channel,message) + if fourInARowTheirTurn: place = emojiToCommand(reaction.emoji) await self.client.gameLoops.fiar(channel," place "+str(piece)+" "+str(place),user.id) + elif addMovieMessage: + moviePick = emojiToCommand(reaction.emoji) + message.delete() + if moviePick == "none": + imdbID = None + else: + imdbID = imdbIds[moviePick-1] + await self.client.bedreNetflix.addMovie(channel,imdbID) elif self.client.funcs.monopolyReactionTest(channel,message): await self.client.gameLoops.runMonopoly(channel,"roll","#"+str(user.id)) elif self.client.funcs.hangmanReactionTest(channel,message) and ord(reaction.emoji) in range(127462,127488): diff --git a/funcs/__init__.py b/funcs/__init__.py index d08c4c9..7a15845 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -10,7 +10,7 @@ from .games import Money, Games from .lookup import spellFunc, monsterFunc -from .other import Generators, movieFunc +from .other import Generators, movieFunc, BedreNetflix from .roll import roll_dice diff --git a/funcs/funcs.py b/funcs/funcs.py index 2562a34..540ce10 100644 --- a/funcs/funcs.py +++ b/funcs/funcs.py @@ -1,6 +1,6 @@ from .miscFuncs import logThis import git # Used by stopServer() -import re +import re, json class Funcs(): def __init__(self,bot): @@ -82,3 +82,14 @@ class Funcs(): gameMessage = True return gameMessage + + def addMovieReactionTest(self,channel,message): + try: + with open("resources/BedreNetflix/oldMessage"+str(channel.id),"r") as f: + data = json.load(f) + except: + return False, None + if data["messageID"] == message.id: + return True, data["imdbIds"] + else: + return False, None \ No newline at end of file diff --git a/funcs/miscFuncs.py b/funcs/miscFuncs.py index 43af7ea..6f77f60 100644 --- a/funcs/miscFuncs.py +++ b/funcs/miscFuncs.py @@ -203,4 +203,6 @@ def emojiToCommand(emoji): return 7 elif emoji == "🎲": return "roll" + elif emoji == "❌": + return "none" else: return "" diff --git a/funcs/other/__init__.py b/funcs/other/__init__.py index 75add9a..7dfa1c3 100644 --- a/funcs/other/__init__.py +++ b/funcs/other/__init__.py @@ -2,5 +2,6 @@ __all__ = ["Generators", "movieFunc"] +from .bedreNetflix import BedreNetflix from .generators import Generators from .movie import movieFunc \ No newline at end of file diff --git a/funcs/other/bedreNetflix.py b/funcs/other/bedreNetflix.py new file mode 100644 index 0000000..7705568 --- /dev/null +++ b/funcs/other/bedreNetflix.py @@ -0,0 +1,75 @@ +import requests, imdb, discord, json +from funcs import logThis + +url = "http://localhost:7878/api/v3/" +moviePath = "/media/plex/Server/movies/" + +class BedreNetflix(): + def __init__(self,bot): + self.bot = bot + + #Returns a list of no more than 5 options when user requests a movie + async def requestMovie(self, ctx, movieName): + logThis("Searching for "+movieName) + movies = imdb.IMDb().search_movie(movieName) + if len(movies) > 5: + movies = movies[:5] + + if len(movies) == 1: + messageTitle = "**Is it this movie?**" + else: + messageTitle = "**Is it any of these movies?**" + + messageText = "" + imdbIds = [] + + for x, movie in enumerate(movies): + messageText += "\n"+str(x+1)+") "+movie["title"]+" ("+str(movie["year"])+")" + imdbIds.append(movie.movieID) + + logThis("Returning a list of "+str(len(movies))+" possible movies: "+str(imdbIds)) + + em = discord.Embed(title=messageTitle,description=messageText,colour=0x00FF00) + + message = await ctx.send(embed=em) + + messageData = {"messageID":message.id,"imdbIds":imdbIds} + + with open("resources/BedreNetflix/oldMessage"+str(ctx.channel.id),"w") as f: + json.dump(messageData,f) + + if len(movies) == 1: + await message.add_reaction("✔️") + else: + for x in range(len(movies)): + await message.add_reaction(["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣"][x]) + + await message.add_reaction("❌") + + #Adds the requested movie to Bedre Netflix + async def addMovie(self,channel,imdbId): + if imdbId == None: + logThis("Did not find what the user was searching for") + await channel.send("Try searching for the IMDB id") + else: + logThis("Trying to add movie "+str(imdbId)) + apiKey = self.bot.credentials.radarrKey + response = requests.get(url+"movie/lookup/imdb?imdbId=tt"+imdbId+"&apiKey="+apiKey) + lookupData = response.json() + postData = {"qualityProfileId": 1, + "rootFolderPath" : moviePath, + "monitored" : True, + "addOptions": {"searchForMovie": True}} + for key in ["tmdbId","title","titleSlug","images","year"]: + postData.update({key : lookupData[key]}) + + r = requests.post(url= url+"movie?apikey="+apiKey,json = postData) + + if r.status_code == 201: + await channel.send("Movie successfully added to Bedre Netflix") + logThis("Added a movie to Bedre Netflix") + elif r.status_code == 400: + await channel.send("The movie is already on Bedre Netflix") + else: + await channel.send("Something went wrong") + logThis(str(r.status_code)+" "+r.reason) diff --git a/resources/help/help-addmovie.txt b/resources/help/help-addmovie.txt new file mode 100644 index 0000000..3d4250a --- /dev/null +++ b/resources/help/help-addmovie.txt @@ -0,0 +1 @@ +Du kan søge efter en film ved at skrive `!addmovie [søgning]`. Gwendolyn vil derefter vise dig resultater baseret på din søgning. Du kan derfra reagere på Gwendolyns besked for at downloade en specefik film. \ No newline at end of file diff --git a/resources/help/help.txt b/resources/help/help.txt index 52fba13..79aa661 100644 --- a/resources/help/help.txt +++ b/resources/help/help.txt @@ -38,4 +38,6 @@ `!wolf` - Lader dig slå ting op på Wolfram Alpha. +`!addmovie` - Lader dig tilføje film til Bedre Netflix. + Du kan få ekstra information om kommandoerne med "!help [kommando]". diff --git a/resources/startingFiles.json b/resources/startingFiles.json index 4639986..205b4d0 100644 --- a/resources/startingFiles.json +++ b/resources/startingFiles.json @@ -59,7 +59,7 @@ "resources/starWars/destinyPoints.txt": "", "resources/movies.txt": "The Room", "resources/names.txt": "Gandalf", - "credentials.txt" : "Bot token: TOKEN\nFinnhub API key: KEY\nWordnik API Key: KEY\nMongoDB user: USERNAME\nMongoDB password: PASSWORD\nWolframAlpha AppID: APPID", + "credentials.txt" : "Bot token: TOKEN\nFinnhub API key: KEY\nWordnik API Key: KEY\nMongoDB user: USERNAME\nMongoDB password: PASSWORD\nWolframAlpha AppID: APPID\nRadarr API key: KEY", "options.txt" : "Prefix: !\nTesting: True" }, "folder" : [ @@ -67,6 +67,7 @@ "resources/games/4InARowBoards", "resources/games/hexBoards", "resources/games/monopolyBoards", - "resources/games/hangmanBoards" + "resources/games/hangmanBoards", + "resources/bedreNetflix" ] } \ No newline at end of file