🎞️ Added !addmovie command
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -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/
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
@ -203,4 +203,6 @@ def emojiToCommand(emoji):
|
||||
return 7
|
||||
elif emoji == "🎲":
|
||||
return "roll"
|
||||
elif emoji == "❌":
|
||||
return "none"
|
||||
else: return ""
|
||||
|
@ -2,5 +2,6 @@
|
||||
|
||||
__all__ = ["Generators", "movieFunc"]
|
||||
|
||||
from .bedreNetflix import BedreNetflix
|
||||
from .generators import Generators
|
||||
from .movie import movieFunc
|
75
funcs/other/bedreNetflix.py
Normal file
75
funcs/other/bedreNetflix.py
Normal file
@ -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)
|
1
resources/help/help-addmovie.txt
Normal file
1
resources/help/help-addmovie.txt
Normal file
@ -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.
|
@ -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]".
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user