CyaOnDaNet Posted January 15, 2020 Share Posted January 15, 2020 (edited) This is a Discord bot that synchronizes with Tautulli and Sonarr to deliver tailored notifications. Important Note about Template Configuration If you have changed your webroot of Sonarr or Tautulli, leave the sonarr_port and or tautulli_port fields blank. Specify the entire base URL in the ip section instead. So for example, if you normally access Tautulli at http://192.168.0.101:8181/tautulli/home instead of the default http://192.168.0.101:8181/home, enter 192.168.0.101:8181/tautulli as the tautulli_ip and leave the tautulli_port field blank. Also, if you access Sonarr or Tautulli with TLS encryption, specify https:// in the beginning of the ip field. Important Note about Images If you want to have images included in your Discord notifications, image hosting must be enabled in Tautulli. Go to Settings > 3rd Party APIs and select an option from the Image Host drop down. Pre-Installation Steps 1. Make sure you have Tautulli and Sonarr setup, they are required to use this bot. 2. Get a Discord Bot Token. To do that go here: https://discordapp.com/developers/applications/me 1. Log in or create an account 2. Click **New App** 3. Fill in App Name and anything else you'd like to include 4. Click **Create App** 5. Click **Create Bot User** * This will provide you with your Bot Token which you will need to place in the docker template 3. Once you have created your bot, you'll need to authorize your bot on a server you have administrative access to. For documentation, you can read: https://discordapp.com/developers/docs/topics/oauth2#bots. The steps are as follows: 1. Go to `https://discordapp.com/api/oauth2/authorize?client_id=[CLIENT_ID]&scope=bot&permissions=1` where [CLIENT_ID] is the Discord App Client ID 2. Select **Add a bot to a server** and select the server to add it to 3. Click **Authorize** 4. You should now see your bot in your server listed as *Offline* Usage This bot allows a mentionable Role to be set as a watching role for users. It gets auto-assigned during playback and removed when playback ends. This is useful for other notifications, like if you need to reboot the Plex server you can ping @watching so they know it's not a problem on their end. To use this feature, the Discord account must be linked to the Plex username with `!link @DiscordUser PlexUsername`. The second usage for this bot is getting relevant recently added notifications. All recently added movies and TV shows are filtered through the bot to add their respective @mentions and then sent in the specified channel. A user chooses their respective notification settings by clicking on emojis and receiving a react-role from the bot. A library can be excluded with the `!notifications library` command, like with a 4K library that most or all of the other users don't have access to. Getting Started After all cofiguration settings have been applied, the bot has been invited to the server, and the bot is online with no errors in the console; you are ready to configure its discord settings. First off, if you want to change the prefix, do it with `!bot prefix newprefix` where newprefix is the actual new prefix. In some sort of Admin only channel, do all the following stuff until the last step. We want to run `!link @DiscordUser PlexUsername` for every user in the server, you can verify the settings with `!linklist` and use `!unlink @DiscordUser` to unlink someone. If you don't know the exact spelling of someone's plex username, the command `!users` will pull a list for you. Now create a Watching Role in Discord and make sure the Mentionable box is ticked. Run this command with the Role you just created `!role @WatchingRole`. If you want to see if its working, run `!bot logchannel #channel` to get a log of the auto-assigning of the role. Run `!bot logchannel off` to disable logging. Run the `!notifications edit` command to setup some notification preferences now. If you have any custom Discord Roles you would like to be React-Roles (so users can opt in and out of them) use the `!notifications custom add @mentionedRole Optional Description` command. Run `!notifications library` to exclude any Plex libraries from recently added notifications. Test the Sonarr connection and generate the database with `!notifications preview`. A database with all shows on Sonarr was just created but only continuing (airing) shows automatically received a discord Role. Now you can edit this list with `!notifications exclude show` or `!notifications include show`. You can even group or ungroup common shows with `!notifications group New Group Name for Shows [show1] [show2] [etc.]` and `!notifications ungroup [show1] [show2] [etc.]`. You can re-call `!notifications preview` to see your changes and once you are satisfied with this list you can continue onto the final step. Finally, you should setup a `#notifications` channel and a `#notifications_settings` channel in Discord. In the channel permissions, non-Admin users should be able to read these messages but not be able to send anything. Also, default server notification settings should be set to @mentions only so people are not spammed by `#notifications` but rather only get notifications on things they want. Use `!notifications channel #notifications` to set the bots recently added notifications to go to the newly created channel and head over to `#notification_settings` and type `!notifications list` to generate all the React-Role embeds. You are now done, and people can receive show specific notifications in your Discord Server! Discord Bot Commands - `!help` : Lists information about commands. - `!help [command name]` : Lists information about a specific command. - `!showlist` : Lists all the shows on Sonarr that are still marked as continuing. - `!bot [subcommand]` : Various bot commands - `!bot info` : Lists current info like logging channel, recently added channel, etc. - `!bot prefix newprefix` : Allows you to change the bot prefix - `!bot logchannel #channel` : Allows you top set the logchannel or turn off logging with `!bot logchannel off` - `!link @DiscordUser PlexUsername` : Links a Discord User Tag with their respective Plex username - `!unlink @DiscordUser PlexUsername` : Unlinks a Discord User Tag with a Plex username - `!linklist` : Shows a list of all linked Plex-Discord Users - `!users` : Lists all Plex usernames that have shared access to the Server, to be used to easily call the `!link @DiscordUser PlexUsername` command. - `!notifications [subcommand]` : - `!notifications edit` : Allows you to edit the page 1 react role options. - `!notifications custom add @mentionedRole Optional Description` : Allows you to add up to 6 custom React-Roles that can be used on page 1 of the `!notifications list` - `!notifications custom remove` : Allows you to remove a custom React-Role - `!notifications library` : Allows you to include or exclude a library from sending recently added notifications. Ex. To exclude a 4k Movie Library from pinging in the `!notifications channel` - `!notifications exclude show` : Excludes a show from getting it's own Role - `!notifications include show` : Includes a show in getting it's own Role - `!notifications group New Group Name for Shows [show1] [show2] [etc.]` : Groups shows as one React-Role - `!notifications ungroup [show1] [show2] [etc.]` : Ungroups previously grouped shows. - `!notifications list` : Lists the react-role embeds to be used for role specified notifications. Should be called in its own channel that others can view but not send in. For now, it needs to be recalled to reflect new changes. - `!notifications preview` : Same as `!notifications list` but does not store embeds in database for emoji recheck on start. Should be used when experimenting in a different channel than the primary #notification_settings. - `!notifications channel #channel` : Sets the channel that recently added shows are notified in. - `!role @WatchingRole` : Assigns the Watching Role that the bot assigns to Users when they are watching Plex. *NOTE: The Bot's Role needs to be higher than the Watching Role* - `!delete` : Deletes all Discord Roles managed by this bot, to be used prior to removing the bot from Server for easy cleanup. Edited February 11, 2020 by CyaOnDaNet Added note about image hosting Quote Link to comment
Fiservedpi Posted January 17, 2020 Share Posted January 17, 2020 (edited) So I got the container pulled down but, having trouble linking it to Sonarr my Sonarr IP and Server IP are the same if that makes any difference Quote message: 'request to http://***>XXX>XX.244:8989/api/series?apikey=XXXXXXXXXXXXXXXXXXXXXXXXXXX failed, reason: connect EHOSTUNREACH http://***>XXX>XX.244:8989, Quote Thank you for this btw.. I think i got it i was using the wrong bot token but still need help with Sonarr EDIT:: I JUST CHANGED MY SONARR IP and it worked Edited January 17, 2020 by Fiservedpi YAAAYYYYYYY!!!! Quote Link to comment
danielg Posted January 17, 2020 Share Posted January 17, 2020 Managed to get everything mostly working but I'm having trouble getting Sonarr to work. When I try to use a Sonarr command like "!notifications list" I get no response and in the logs it shows this. Any Ideas? TypeError: Only HTTP(S) protocols are supported at getNodeRequestOptions (/app/node_modules/node-fetch/lib/index.js:1303:9) at /app/node_modules/node-fetch/lib/index.js:1404:19 at new Promise (<anonymous>) at fetch (/app/node_modules/node-fetch/lib/index.js:1401:9) at sonarrService.getSeries (/app/src/sonarr.js:14:32) at Object.updateShowList (/app/index.js:828:40) at Object.execute (/app/commands/notifications.js:1274:25) at Client.<anonymous> (/app/index.js:218:12) at Client.emit (events.js:223:5) at MessageCreateHandler.handle (/app/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34) Couldn't connect to Sonarr, check your settings. Quote Link to comment
CyaOnDaNet Posted January 17, 2020 Author Share Posted January 17, 2020 I apologize for the sonarr bug, I actually pushed an update that broke it without realizing it. It's fixed now, if you go to your container and force an update it should be good. Quote Link to comment
CyaOnDaNet Posted January 17, 2020 Author Share Posted January 17, 2020 5 hours ago, Fiservedpi said: So I got the container pulled down but, having trouble linking it to Sonarr my Sonarr IP and Server IP are the same if that makes any difference I think i got it i was using the wrong bot token but still need help with Sonarr EDIT:: I JUST CHANGED MY SONARR IP and it worked Sorry about the sonarr bug, I actually pushed an update that broke it without realizing it. It's fixed now, if you go to your container settings and force an update it should be fixed. I see in that screen capture that the Discord User wasn't linked to a Plex User. Did you type the command as: !link @DiscordUser PlexUserName Quote Link to comment
danielg Posted January 17, 2020 Share Posted January 17, 2020 (edited) 50 minutes ago, CyaOnDaNet said: I apologize for the sonarr bug, I actually pushed an update that broke it without realizing it. It's fixed now, if you go to your container and force an update it should be good. Thanks for the quick response! Though, I'm not seeing an update and still have the same issue. Edited January 17, 2020 by danielg Quote Link to comment
CyaOnDaNet Posted January 17, 2020 Author Share Posted January 17, 2020 3 hours ago, danielg said: Thanks for the quick response! Though, I'm not seeing an update and still have the same issue. Interesting, I just pushed a new update so check your docker updates and apply. The command `!bot info` should now state the bot version so if you see 1.1.4 then you have the latest. Let me know if you have the same issue after this update. Quote Link to comment
Fiservedpi Posted January 17, 2020 Share Posted January 17, 2020 (edited) If my Sonarr and Unraid share the same ip (HOST) but different port # the container won't connect to Sonarr but if I put Sonarr on a different adapter (Br0) it connects but that doesn't work for me, as changing my Sonarr IP breaks SAB for me any idea why I'm getting the EHOSTUNREAC error or how to fix it Edited January 17, 2020 by Fiservedpi Edit Quote Link to comment
danielg Posted January 17, 2020 Share Posted January 17, 2020 6 hours ago, CyaOnDaNet said: Interesting, I just pushed a new update so check your docker updates and apply. The command `!bot info` should now state the bot version so if you see 1.1.4 then you have the latest. Let me know if you have the same issue after this update. Ahhh, had to switch to advanced view and force update. All is working now! Thanks Quote Link to comment
CyaOnDaNet Posted January 17, 2020 Author Share Posted January 17, 2020 6 hours ago, Fiservedpi said: If my Sonarr and Unraid share the same ip (HOST) but different port # the container won't connect to Sonarr but if I put Sonarr on a different adapter (Br0) it connects but that doesn't work for me, as changing my Sonarr IP breaks SAB for me any idea why I'm getting the EHOSTUNREAC error or how to fix it Hmm, I'm not sure why a different IP would be causing that issue. Mine is running on the same host IP and I have no issues. Is there anything else in the log other than that one line of EHOSTUNREAC? Is that request line in the format of: http://192.168.1.50:8989/api/series?apikey=XXXXXXXXXXXXXXXXXXXXXXXXXXX Quote Link to comment
Fiservedpi Posted January 17, 2020 Share Posted January 17, 2020 (edited) I just moved all containers pertaining to Nzbing to the bridge adapter setting and are now communicating nicely. Thanks again Edited January 17, 2020 by Fiservedpi Quote Link to comment
CyaOnDaNet Posted January 17, 2020 Author Share Posted January 17, 2020 22 minutes ago, Fiservedpi said: I just moved all containers pertaining to Nzbing to the bridge adapter setting and are now not communicating nicely. Thanks again You stated not here so I'm a little confused. Is everything working on the bridge adapter now? Quote Link to comment
Fiservedpi Posted January 17, 2020 Share Posted January 17, 2020 Sorry yes everything is good Quote Link to comment
CyaOnDaNet Posted January 17, 2020 Author Share Posted January 17, 2020 Just now, Fiservedpi said: Sorry yes everything is good Okay, cool, glad to hear. That was a weird issue you were having and I may need to dig a little deeper if someone else has the same problem. Quote Link to comment
Bolagnaise Posted January 18, 2020 Share Posted January 18, 2020 I cannot get it to connect to Tautulli, keeps getting this error. Api access is enabled in tautulli and its the correct api key. message: 'invalid json response body at http://192.168.0.101:8181/api/v2?apikey=''TOKENREMOVED''&cmd=get_activity reason: Unexpected token < in JSON at position 0', Quote Link to comment
CyaOnDaNet Posted January 18, 2020 Author Share Posted January 18, 2020 3 minutes ago, Bolagnaise said: I cannot get it to connect to Tautulli, keeps getting this error. Api access is enabled in tautulli and its the correct api key. message: 'invalid json response body at http://192.168.0.101:8181/api/v2?apikey=''TOKENREMOVED''&cmd=get_activity reason: Unexpected token < in JSON at position 0', That's strange, is there anything else in the logs? I imagine its referring to the tautulli.js file at line 104 but I'm not sure what could cause an error like this. After some searching it appears that a TLS encrypted tautulli could have caused this. Do you by chance normally access tautulli with https? If so, just add that to your ip, so for your case it would be https://192.168.0.101 in the ip section of the template. Quote Link to comment
Bolagnaise Posted January 18, 2020 Share Posted January 18, 2020 1 hour ago, CyaOnDaNet said: TLS encrypted tautulli Not turned on, More errors now appearing FetchError: invalid json response body at http://192.168.0.101:8181/api/v2?apikey=XXXmd=get_notifiers reason: Unexpected token < in JSON at position 0 at /app/node_modules/node-fetch/lib/index.js:272:32 at processTicksAndRejections (internal/process/task_queues.js:94:5) at async module.exports (/app/src/tautulli.js:214:18) { message: 'invalid json response body at http://192.168.0.101:8181/api/v2?apikey=XXXmd=get_notifiers reason: Unexpected token < in JSON at position 0', type: 'invalid-json' Quote Link to comment
CyaOnDaNet Posted January 18, 2020 Author Share Posted January 18, 2020 44 minutes ago, Bolagnaise said: Unexpected token < in JSON at position 0', type: 'invalid-json' After doing some more digging, I discovered that Tautulli's api can also return xml even though json is the default. Since it returned with < at position 0, I can only assume it returned xml. I made some changes to force it to return json and the container update is live, its bot version 1.1.5. Click on the advanced view in docker containers to force an update now or click check for updates at the bottom of the docker page and then apply update. If it's still returning this same error after the update let me know and I will enable some more debugging to see whats going on. Quote Link to comment
Bolagnaise Posted January 18, 2020 Share Posted January 18, 2020 (edited) 20 minutes ago, CyaOnDaNet said: I will enable some more debugging to see whats going on. same issue still happening. FetchError: invalid json response body at http://192.168.0.101:8181/api/v2?apikey=xxcmd=get_activity&out_type=json reason: Unexpected token < in JSON at position 0 at /app/node_modules/node-fetch/lib/index.js:272:32 at processTicksAndRejections (internal/process/task_queues.js:94:5) at async tautulliService.getActivity (/app/src/tautulli.js:107:22) at async Job.job (/app/index.js:250:15) { Going to the link in the log i get this https://gyazo.com/5b11cb1597245f506c1839d501eed915 Edited January 18, 2020 by Bolagnaise Quote Link to comment
Bolagnaise Posted January 18, 2020 Share Posted January 18, 2020 52 minutes ago, CyaOnDaNet said: After doing some more digging, I discovered that Tautulli's api can also return xml even though json is the default. Since it returned with < at position 0, I can only assume it returned xml. I made some changes to force it to return json and the container update is live, its bot version 1.1.5. Click on the advanced view in docker containers to force an update now or click check for updates at the bottom of the docker page and then apply update. If it's still returning this same error after the update let me know and I will enable some more debugging to see whats going on. I have googled the shit out of it, i think it might have something to do with me using a base url for a reverse proxy Quote Link to comment
CyaOnDaNet Posted January 18, 2020 Author Share Posted January 18, 2020 29 minutes ago, Bolagnaise said: same issue still happening. First off, thanks for the log info and that screen capture. You clearly have the ip and port correct because of the "Powered by CherryPy 5.1.0" footer. If the api key was wrong it would still return a json saying invalid API key. Instead, its returning a html 404 error which is why the bot doesn't errors. I can reproduce the same 404 error page on my own Tautuill service by entering an invalid path. It's like your Tautulli api endpoint doesn't exist. This is very strange. The only thing I can suggest right now is to check if your Tautulli is up-to-date but I doubt that will make a difference. I am in communication with the Tautulli Discord support channel to see as to why your endpoint is not working. I will get back to you when someone offers a solution. Sorry if I could not be of more help at this current moment. Quote Link to comment
Bolagnaise Posted January 18, 2020 Share Posted January 18, 2020 Just now, CyaOnDaNet said: First off, thanks for the log info and that screen capture. You clearly have the ip and port correct because of the "Powered by CherryPy 5.1.0" footer. If the api key was wrong it would still return a json saying invalid API key. Instead, its returning a html 404 error which is why the bot doesn't errors. I can reproduce the same 404 error page on my own Tautuill service by entering an invalid path. It's like your Tautulli api endpoint doesn't exist. This is very strange. The only thing I can suggest right now is to check if your Tautulli is up-to-date but I doubt that will make a difference. I am in communication with the Tautulli Discord support channel to see as to why your endpoint is not working. I will get back to you when someone offers a solution. Sorry if I could not be of more help at this current moment. No problems, im going to uninstall the linuxserver version and try the Tautulli version. Quote Link to comment
CyaOnDaNet Posted January 18, 2020 Author Share Posted January 18, 2020 1 minute ago, Bolagnaise said: No problems, im going to uninstall the linuxserver version and try the Tautulli version. For what its worth, I'm using the linuxserver version and its fine. My web interface settings look like this and its behind a nginx proxy but the bot accesses it locally so it has no problems. 6 minutes ago, Bolagnaise said: I have googled the shit out of it, i think it might have something to do with me using a base url for a reverse proxy Did you change the HTTP Root section? Quote Link to comment
CyaOnDaNet Posted January 18, 2020 Author Share Posted January 18, 2020 10 minutes ago, Bolagnaise said: I have googled the shit out of it, i think it might have something to do with me using a base url for a reverse proxy Also, does http://192.168.0.101:8181/home take you to your Tautulli home page? If it does, I imagine the base url change shouldn't have effected the api. Quote Link to comment
Bolagnaise Posted January 18, 2020 Share Posted January 18, 2020 (edited) 58 minutes ago, CyaOnDaNet said: Also, does http://192.168.0.101:8181/home take you to your Tautulli home page? If it does, I imagine the base url change shouldn't have effected the api. yes it does, (well http://192.168.0.101:8181/tautulli/home does) so it seems its not the issue, i installed the default tautulli, same issue. Best bet is too nuke everything i guess Edited January 18, 2020 by Bolagnaise Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.