cr fix
This commit is contained in:
parent
63035eea8d
commit
e528b9600b
26
README.md
26
README.md
|
@ -470,17 +470,15 @@ Can be used to post a picture from giphy given a query string.
|
||||||
|
|
||||||
API Key:
|
API Key:
|
||||||
|
|
||||||
The module has no API Key set up by defualt. You have to provide an api key by setting the environment variable `GIPHY_API_KEY`.
|
The module has no API Key set up by default. You have to provide an api key by using the relevant command.
|
||||||
|
|
||||||
Read the documentation to create one at https://developers.giphy.com/docs/api
|
Read the documentation to create one at https://developers.giphy.com/docs/api
|
||||||
|
|
||||||
Environ variables seen by commands:
|
|
||||||
|
|
||||||
* GIPHY_API_KEY: API Key for Giphy access
|
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
* !giphy "query" - Post the first image result from giphy for the given "query"
|
* !giphy apikey [apikey] - Set api key (Must be done as bot owner)
|
||||||
|
* !giphy [query] - Post the first image result from giphy for the given [query]
|
||||||
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -492,7 +490,7 @@ Can be used to post a picture from Gfycat given a query string.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
* !gfycat "query" - Post the first image result from gfycat for the given "query"
|
* !gfycat [query] - Post the first image result from gfycat for the given [query]
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -504,26 +502,24 @@ Can be used to fetch recently added information from Tautulli or receive Tautull
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
|
* !tautulli apikey [apikey] - Set api key (Must be done as bot owner)
|
||||||
* !tautulli movie - Show the last 10 recently added movies to Plex library monitered by Tautulli
|
* !tautulli movie - Show the last 10 recently added movies to Plex library monitered by Tautulli
|
||||||
* !tautulli show - Show the last 10 recently added tv series epsiodes to Plex library monitered by Tautulli
|
* !tautulli show - Show the last 10 recently added tv series epsiodes to Plex library monitered by Tautulli
|
||||||
* !tautulli artist - Show the last 10 recently added music artists to Plex library monitered by Tautulli
|
* !tautulli artist - Show the last 10 recently added music artists to Plex library monitered by Tautulli
|
||||||
* !tautulli add "room_id" encrypted - Add the provided encrypted "room_id" to the list of rooms to post the recently added notifications received by the webhook
|
* !tautulli add [room_id] encrypted - Add the provided encrypted [room_id] to the list of rooms to post the recently added notifications received by the webhook
|
||||||
* !tautulli add "room_id" plain - Add the provided unencrypted "room_id" to the list of rooms to post the recently added notifications received by the webhook
|
* !tautulli add [room_id] plain - Add the provided unencrypted [room_id] to the list of rooms to post the recently added notifications received by the webhook
|
||||||
* !tautulli remove "room_id" encrypted - Remove the provided encrypted "room_id" to the list of rooms to post the recently added notifications received by the webhook
|
* !tautulli remove [room_id] encrypted - Remove the provided encrypted [room_id] to the list of rooms to post the recently added notifications received by the webhook
|
||||||
* !tautulli remove "room_id" plain - Remove the provided unencrypted "room_id" to the list of rooms to post the recently added notifications received by the webhook
|
* !tautulli remove [room_id] plain - Remove the provided unencrypted [room_id] to the list of rooms to post the recently added notifications received by the webhook
|
||||||
|
|
||||||
Tautulli instance and API Key:
|
Tautulli instance and API Key:
|
||||||
|
|
||||||
The module work with an existing installed instance of Tautulli accessible on the machine at the path defined by env variable `TAUTULLI_PATH`
|
The module work with an existing installed instance of Tautulli accessible on the machine at the path defined by env variable `TAUTULLI_PATH`
|
||||||
You have to provide an api key by setting the environment variable `TAUTULLI_API_KEY`.
|
You have to provide an api key by using the relevant command.
|
||||||
|
|
||||||
Read the documentation to create one at https://developers.giphy.com/docs/api
|
|
||||||
|
|
||||||
Environ variables seen by commands:
|
Environ variables seen by commands:
|
||||||
|
|
||||||
* TAUTULLI_PATH: Path accessible from the machine to the installed instance of Tautulli
|
* TAUTULLI_PATH: Path accessible from the machine to the installed instance of Tautulli
|
||||||
* TAUTULLI_URL: Url accessible from the machine to the installed instance of Tautulli
|
* TAUTULLI_URL: Url accessible from the machine to the installed instance of Tautulli
|
||||||
* TAUTULLI_API_KEY: API Key for Tautulli access
|
|
||||||
* TAUTULLI_NOTIFIER_ADDR: Listening address for the Tautulli webhook handler target
|
* TAUTULLI_NOTIFIER_ADDR: Listening address for the Tautulli webhook handler target
|
||||||
* TAUTULLI_NOTIFIER_PORT: Listening port for the Tautulli webhook handler target
|
* TAUTULLI_NOTIFIER_PORT: Listening port for the Tautulli webhook handler target
|
||||||
* BOT_OWNERS: Owner of the rooms in the list for the notification webhook
|
* BOT_OWNERS: Owner of the rooms in the list for the notification webhook
|
||||||
|
|
|
@ -12,13 +12,21 @@ from collections import namedtuple
|
||||||
from modules.common.module import BotModule
|
from modules.common.module import BotModule
|
||||||
|
|
||||||
class MatrixModule(BotModule):
|
class MatrixModule(BotModule):
|
||||||
|
api_key = None
|
||||||
|
|
||||||
async def matrix_message(self, bot, room, event):
|
async def matrix_message(self, bot, room, event):
|
||||||
args = event.body.split()
|
args = event.body.split()
|
||||||
if len(args) > 1:
|
if len(args) == 3 and args[1] == 'apikey':
|
||||||
|
bot.must_be_owner(event)
|
||||||
|
|
||||||
|
self.api_key = args[2]
|
||||||
|
bot.save_settings()
|
||||||
|
await bot.send_text(room, 'Api key set')
|
||||||
|
elif len(args) > 1:
|
||||||
gif_url = "No image found"
|
gif_url = "No image found"
|
||||||
query = event.body[len(args[0])+1:]
|
query = event.body[len(args[0])+1:]
|
||||||
try:
|
try:
|
||||||
g = giphypop.Giphy(api_key=os.getenv("GIPHY_API_KEY"))
|
g = giphypop.Giphy(api_key=self.api_key)
|
||||||
gifs = []
|
gifs = []
|
||||||
try:
|
try:
|
||||||
for x in g.search(phrase=query, limit=1):
|
for x in g.search(phrase=query, limit=1):
|
||||||
|
@ -38,8 +46,15 @@ class MatrixModule(BotModule):
|
||||||
else:
|
else:
|
||||||
await bot.send_text(room, 'Usage: !giphy <query>')
|
await bot.send_text(room, 'Usage: !giphy <query>')
|
||||||
|
|
||||||
|
def get_settings(self):
|
||||||
|
data = super().get_settings()
|
||||||
|
data["api_key"] = self.api_key
|
||||||
|
return data
|
||||||
|
|
||||||
def set_settings(self, data):
|
def set_settings(self, data):
|
||||||
super().set_settings(data)
|
super().set_settings(data)
|
||||||
|
if data.get("api_key"):
|
||||||
|
self.api_key = data["api_key"]
|
||||||
|
|
||||||
def help(self):
|
def help(self):
|
||||||
return ('Giphy bot')
|
return ('Giphy bot')
|
||||||
|
|
|
@ -123,6 +123,7 @@ class WebServer:
|
||||||
class MatrixModule(BotModule):
|
class MatrixModule(BotModule):
|
||||||
httpd = None
|
httpd = None
|
||||||
rooms = dict()
|
rooms = dict()
|
||||||
|
api_key = None
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
|
@ -151,14 +152,20 @@ class MatrixModule(BotModule):
|
||||||
|
|
||||||
async def matrix_message(self, bot, room, event):
|
async def matrix_message(self, bot, room, event):
|
||||||
args = event.body.split()
|
args = event.body.split()
|
||||||
if len(args) == 2:
|
if len(args) == 3 and args[1] == 'apikey':
|
||||||
|
bot.must_be_owner(event)
|
||||||
|
|
||||||
|
self.api_key = args[2]
|
||||||
|
bot.save_settings()
|
||||||
|
await bot.send_text(room, 'Api key set')
|
||||||
|
elif len(args) == 2:
|
||||||
media_type = args[1]
|
media_type = args[1]
|
||||||
if media_type != "movie" and media_type != "show" and media_type != "artist":
|
if media_type != "movie" and media_type != "show" and media_type != "artist":
|
||||||
await bot.send_text(room, "media type '%s' provided not valid" % media_type)
|
await bot.send_text(room, "media type '%s' provided not valid" % media_type)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = "{}/api/v2?apikey={}&cmd=get_recently_added&count=10".format(os.getenv("TAUTULLI_URL"), os.getenv("TAUTULLI_API_KEY"))
|
url = "{}/api/v2?apikey={}&cmd=get_recently_added&count=10".format(os.getenv("TAUTULLI_URL"), self.api_key)
|
||||||
req = urllib.request.Request(url+"&media_type="+media_type)
|
req = urllib.request.Request(url+"&media_type="+media_type)
|
||||||
connection = urllib.request.urlopen(req).read()
|
connection = urllib.request.urlopen(req).read()
|
||||||
entries = json.loads(connection)
|
entries = json.loads(connection)
|
||||||
|
@ -194,6 +201,7 @@ class MatrixModule(BotModule):
|
||||||
|
|
||||||
def get_settings(self):
|
def get_settings(self):
|
||||||
data = super().get_settings()
|
data = super().get_settings()
|
||||||
|
data["api_key"] = self.api_key
|
||||||
data["rooms"] = self.rooms
|
data["rooms"] = self.rooms
|
||||||
self.httpd.rooms = self.rooms
|
self.httpd.rooms = self.rooms
|
||||||
return data
|
return data
|
||||||
|
@ -203,6 +211,8 @@ class MatrixModule(BotModule):
|
||||||
if data.get("rooms"):
|
if data.get("rooms"):
|
||||||
self.rooms = data["rooms"]
|
self.rooms = data["rooms"]
|
||||||
self.httpd.rooms = self.rooms
|
self.httpd.rooms = self.rooms
|
||||||
|
if data.get("api_key"):
|
||||||
|
self.api_key = data["api_key"]
|
||||||
|
|
||||||
def help(self):
|
def help(self):
|
||||||
return ('Tautulli recently added bot')
|
return ('Tautulli recently added bot')
|
||||||
|
|
Loading…
Reference in New Issue