📽️ Added the !addshow command
This commit is contained in:
@ -18,6 +18,7 @@ class Credentials():
|
||||
self.mongoDBPassword = data[4][17:].replace(" ","")
|
||||
self.wolfKey = data[5][19:].replace(" ","")
|
||||
self.radarrKey = data[6][15:].replace(" ","")
|
||||
self.sonarrKey = data[7][15:].replace(" ","")
|
||||
|
||||
class Options():
|
||||
def __init__(self):
|
||||
|
@ -122,10 +122,15 @@ class MiscCog(commands.Cog):
|
||||
await ctx.send(content)
|
||||
|
||||
#Searches for movie and adds it to Bedre Netflix
|
||||
@commands.command(aliases = ["rm","addmovie"])
|
||||
@commands.command(aliases = ["rm","addmovie","am"])
|
||||
async def requestmovie(self, ctx, *, content):
|
||||
await self.bedreNetflix.requestMovie(ctx,content)
|
||||
|
||||
#Searches for show and adds it to Bedre Netflix
|
||||
@commands.command(aliases = ["rs","addshow","as"])
|
||||
async def requestshow(self, ctx, *, content):
|
||||
await self.bedreNetflix.requestShow(ctx,content)
|
||||
|
||||
#Looks up on Wolfram Alpha
|
||||
@commands.command()
|
||||
async def wolf(self, ctx, *, content):
|
||||
|
@ -18,12 +18,12 @@ class ReactionCog(commands.Cog):
|
||||
except:
|
||||
fourInARowTheirTurn = False
|
||||
|
||||
addMovieMessage, imdbIds = self.client.funcs.addMovieReactionTest(channel,message)
|
||||
bedreNetflixMessage, addMovie, imdbIds = self.client.funcs.bedreNetflixReactionTest(channel,message)
|
||||
|
||||
if fourInARowTheirTurn:
|
||||
place = emojiToCommand(reaction.emoji)
|
||||
await self.client.gameLoops.fiar(channel," place "+str(piece)+" "+str(place),user.id)
|
||||
elif addMovieMessage:
|
||||
elif bedreNetflixMessage and addMovie:
|
||||
moviePick = emojiToCommand(reaction.emoji)
|
||||
await message.delete()
|
||||
if moviePick == "none":
|
||||
@ -31,6 +31,14 @@ class ReactionCog(commands.Cog):
|
||||
else:
|
||||
imdbID = imdbIds[moviePick-1]
|
||||
await self.client.bedreNetflix.addMovie(channel,imdbID)
|
||||
elif bedreNetflixMessage and not addMovie:
|
||||
showPick = emojiToCommand(reaction.emoji)
|
||||
await message.delete()
|
||||
if showPick == "none":
|
||||
imdbName = None
|
||||
else:
|
||||
imdbName = imdbIds[showPick-1]
|
||||
await self.client.bedreNetflix.addShow(channel,imdbName)
|
||||
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):
|
||||
|
@ -83,13 +83,16 @@ class Funcs():
|
||||
|
||||
return gameMessage
|
||||
|
||||
def addMovieReactionTest(self,channel,message):
|
||||
def bedreNetflixReactionTest(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"]
|
||||
if "imdbIds" in data:
|
||||
return True, True, data["imdbIds"]
|
||||
else:
|
||||
return True, False, data["imdbNames"]
|
||||
else:
|
||||
return False, None
|
@ -205,4 +205,6 @@ def emojiToCommand(emoji):
|
||||
return "roll"
|
||||
elif emoji == "❌":
|
||||
return "none"
|
||||
elif emoji == "✔️":
|
||||
return 1
|
||||
else: return ""
|
||||
|
@ -1,8 +1,10 @@
|
||||
import requests, imdb, discord, json
|
||||
from funcs import logThis
|
||||
|
||||
url = "http://localhost:7878/api/v3/"
|
||||
radarrURL = "http://localhost:7878/api/v3/"
|
||||
sonarrURL = "http://192.168.0.40:8989/api/"
|
||||
moviePath = "/media/plex/Server/movies/"
|
||||
showPath = "/media/plex/Server/Shows/"
|
||||
|
||||
class BedreNetflix():
|
||||
def __init__(self,bot):
|
||||
@ -11,7 +13,11 @@ class BedreNetflix():
|
||||
#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)
|
||||
movieList = imdb.IMDb().search_movie(movieName)
|
||||
movies = []
|
||||
for movie in movieList:
|
||||
if movie["kind"] == "movie":
|
||||
movies.append(movie)
|
||||
if len(movies) > 5:
|
||||
movies = movies[:5]
|
||||
|
||||
@ -54,7 +60,7 @@ class BedreNetflix():
|
||||
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)
|
||||
response = requests.get(radarrURL+"movie/lookup/imdb?imdbId=tt"+imdbId+"&apiKey="+apiKey)
|
||||
lookupData = response.json()
|
||||
postData = {"qualityProfileId": 1,
|
||||
"rootFolderPath" : moviePath,
|
||||
@ -63,7 +69,7 @@ class BedreNetflix():
|
||||
for key in ["tmdbId","title","titleSlug","images","year"]:
|
||||
postData.update({key : lookupData[key]})
|
||||
|
||||
r = requests.post(url= url+"movie?apikey="+apiKey,json = postData)
|
||||
r = requests.post(url= radarrURL+"movie?apikey="+apiKey,json = postData)
|
||||
|
||||
if r.status_code == 201:
|
||||
await channel.send("Movie successfully added to Bedre Netflix")
|
||||
@ -73,3 +79,73 @@ class BedreNetflix():
|
||||
else:
|
||||
await channel.send("Something went wrong")
|
||||
logThis(str(r.status_code)+" "+r.reason)
|
||||
|
||||
#Returns a list of no more than 5 options when user requests a show
|
||||
async def requestShow(self, ctx, showName):
|
||||
logThis("Searching for "+showName)
|
||||
movies = imdb.IMDb().search_movie(showName) #Replace with tvdb
|
||||
shows = []
|
||||
for movie in movies:
|
||||
if movie["kind"] == "tv series":
|
||||
shows.append(movie)
|
||||
if len(shows) > 5:
|
||||
shows = shows[:5]
|
||||
|
||||
if len(shows) == 1:
|
||||
messageTitle = "**Is it this show?**"
|
||||
else:
|
||||
messageTitle = "**Is it any of these shows?**"
|
||||
|
||||
messageText = ""
|
||||
imdbNames = []
|
||||
|
||||
for x, show in enumerate(shows):
|
||||
messageText += "\n"+str(x+1)+") "+show["title"]+" ("+str(show["year"])+")"
|
||||
imdbNames.append(show["title"])
|
||||
|
||||
logThis("Returning a list of "+str(len(shows))+" possible shows: "+str(imdbNames))
|
||||
|
||||
em = discord.Embed(title=messageTitle,description=messageText,colour=0x00FF00)
|
||||
|
||||
message = await ctx.send(embed=em)
|
||||
|
||||
messageData = {"messageID":message.id,"imdbNames":imdbNames}
|
||||
|
||||
with open("resources/bedreNetflix/oldMessage"+str(ctx.channel.id),"w") as f:
|
||||
json.dump(messageData,f)
|
||||
|
||||
if len(shows) == 1:
|
||||
await message.add_reaction("✔️")
|
||||
else:
|
||||
for x in range(len(shows)):
|
||||
await message.add_reaction(["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣"][x])
|
||||
|
||||
await message.add_reaction("❌")
|
||||
|
||||
#Adds the requested show to Bedre Netflix
|
||||
async def addShow(self,channel,imdbName):
|
||||
if imdbName == 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 show "+str(imdbName))
|
||||
apiKey = self.bot.credentials.sonarrKey
|
||||
response = requests.get(sonarrURL+"series/lookup?term="+imdbName.replace(" ","%20")+"&apiKey="+apiKey)
|
||||
lookupData = response.json()[0]
|
||||
postData = {"ProfileId" : 1,
|
||||
"rootFolderPath" : showPath,
|
||||
"monitored" : True,
|
||||
"addOptions" : {"searchForMissingEpisodes" : True}}
|
||||
for key in ["tvdbId","title","titleSlug","images","seasons"]:
|
||||
postData.update({key : lookupData[key]})
|
||||
|
||||
r = requests.post(url= sonarrURL+"series?apikey="+apiKey,json = postData)
|
||||
|
||||
if r.status_code == 201:
|
||||
await channel.send("Show successfully added to Bedre Netflix")
|
||||
logThis("Added a show to Bedre Netflix")
|
||||
elif r.status_code == 400:
|
||||
await channel.send("The show is already on Bedre Netflix")
|
||||
else:
|
||||
await channel.send("Something went wrong")
|
||||
logThis(str(r.status_code)+" "+r.reason)
|
||||
|
@ -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\nRadarr API key: KEY",
|
||||
"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\nSonarr API key: KEY",
|
||||
"options.txt" : "Prefix: !\nTesting: True"
|
||||
},
|
||||
"folder" : [
|
||||
|
Reference in New Issue
Block a user