Skip to content

Commit

Permalink
Implemented posting Twitch Live notifications to Discord Channels (#140)
Browse files Browse the repository at this point in the history
* Implemented verification for POST requests to ensure the message is from Twitch

* Added basic logging to TwitchListener

* Added TwitchApp class to handle any data the Request handler needs to keep between requests

* Added docstring to existing methods

* Implemented send_webhook so that notifications get sent to their respective channels.

* updated requirements.txt

* updated generate_schema.py

* updated gitignore

* Implemented the TwitchCog with hook creation and account adding

* Added removetwitch and listtwitch commands

* Added remove twitch hook command

* Added docstrings to command methods

* Changed CALLBACK_URL to use env var

* addtwitch channel now accepts a string for the custom message and also supports sending a twitch url as the channel

* Added user facing strings

* Added command to set custom message

* Added command to get custom message

* Applied YAPF formatter

* Added check to not allow webhook names to be the webhook prefix

* Moved all commands to be subcommand of `twitch`

* Changed module name to reflect new module name in bot start

* Ensured consistency of use of the word channel over account when refering to a Twitch channel

* Added help and usage strings to commands

* Fixed an bug that caused an error when given a Twitch channel that doesn't exists

* Made channel names in user strings be inline code blocks for easier reading

* Fixed missing turning list into a dict for channel info

* Added new string for channels that are not tracked but are real channels

* Added check for empty environment variables

* Updated some logging lines

* Applied YAPF formatter

* Fixed typos

* Added module docstring

* Notifications now include the custom 'go live' message

* Added preview command to see what a notification for a channel will look like

* Applied YAPF formatting

* Deleted TwitchIntegrationCog

* Implemented new DB accessor

* Moved load_discord_hooks to discordUtil

* Made reusable functions for loading/saving bearer tokens

* Updated load_tracked_channels docstring to be more consistent.

* Fixed some booleans to be simpler

* Moved more functions to discordUtil for shared access

* Made global twitch api strings

* Fixed an issue where PyCharm doesn't recognise application as the correct class

* Added filter to for to avoid needing to check for membership

* Exposed port 443

* Fixed an issue where if the twitch temp file did not exist it would fail to start

* Fixed an issue caused by changing of program starting dir

* Changed createhook command to require a name and channel as parameters

* Updated how notifications are posted for channels so that a channel now is tied to a specific webhook instead of the server as a whole.

- This change was made with the Esports Hub in mind where different games may not care about other games' streams.

* Updated README to include the changes to Webhooks and the tracking of channels
  • Loading branch information
Fluxticks authored Aug 19, 2021
1 parent fa9c188 commit 0ddeeb8
Show file tree
Hide file tree
Showing 8 changed files with 1,227 additions and 78 deletions.
52 changes: 38 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,52 @@ In your `.env` file the `TWITCH_SUB_SECRET` should be a string that is 10-100 ch
The `TWITCH_CALLBACK` is the URL to your HTTPS server. For testing you can use `ngrok`:
- Run `ngrok http 443` and copy the `https` URL **not** the `htttp` URL and use that as your `TWITCH_CALLBACK` variable.

#### !twitch createhook [optional: channel_mention] [optional: hook name]
* Creates a Discord Webhook bound to the channel the command was executed in, unless a channel is given, and with a default name unless a name is given.
#### !twitch createhook \<channel mention> \<hook name>
* Aliases: `newhook, makehook, addhook`
* Creates a new Discord Webhook bound to the mentioned channel.
The name will be prefixed with the Twitch Cog Webhook prefix to distinguish Twitch hooks from other Webhooks.
The Webhooks created with the Twitch Cog do not need the prefix used in the name in order to reference them.
* *Requires `administrator` permission in Discord*

#### !twitch deletehook \<hook name>
* Deletes the given Discord Webhook.
* *Requires `administrator` permission in Discord*

#### !twitch add \<twitch handle | twitch url> [optional: custom message]
* Adds a Twitch channel to be tracked in the current Discord server.
* *__If a custom message is given, it must be surrounded by double quotes__*: `!twitch add <twitch_handle> "custom_message"`
#### !twitch add \<twitch handle | twitch url> \<webhook name> [optional: custom message]
* Adds a Twitch channel to be tracked in the given Webhook.
This means when the channel goes live, its notification will be posted to the given Webhook.
A channel can be tied to more than one Webhook.
The custom message can be left empty, but when not, it will be used in the live notification.
A preview of what a notification looks like can be seen with the `!twitch preview <twitch handle> <webhook name>` command.
* *__If a custom message is given, it must be surrounded by double quotes__*: `!twitch add <twitch_handle> <webhook name> "custom_message"`
* *Requires `administrator` permission in Discord*

#### !twitch remove \<twitch handle>
* Removes a Twitch channel from being tracked in the current Discord server.
#### !twitch remove \<twitch handle> \<webhook name>
* Removes a Twitch channel from being tracked in the given Webhook.
* *Requires `administrator` permission in Discord*

#### !twitch list
* Shows a list of all the currently tracked Twitch accounts and their custom messages.
#### !twitch list [optional: webhook name]
* Shows a list of all the currently tracked Twitch accounts and their custom messages for the given Webhook.
If no Webhook name is given, it shows the information for all Twitch Webhooks.
* *Requires `administrator` permission in Discord*

#### !twitch setmessage \<twitch handle> [optional: custom message]
* Sets the custom message of a Twitch channel. Can be left empty if the custom message is to be removed.
* *__If a custom message is given, it must be surrounded by double quotes__*: `!twitch setmessage <twitch_handle> "custom_message"`
#### !twitch webhooks
* Shows a list of the current Webhooks for the Twitch Cog.
* *Requires `administrator` permission in Discord*

#### !twitch setmessage \<twitch handle> \<webhook name> [optional: custom message]
* Sets the custom message of a Twitch channel for the given Webhook.
Can be left empty if the custom message is to be removed.
* *__If a custom message is given, it must be surrounded by double quotes__*: `!twitch setmessage <twitch_handle> <webhook name> "custom_message"`
* *Requires `administrator` permission in Discord*

#### !twitch getmessage \<twitch handle>
* Gets the currently set custom message for a Twitch channel.
#### !twitch getmessage \<twitch handle> [optional: webhook name]
* Gets the currently set custom message for a Twitch channel for the given Webhook.
If no Webhook name is given, it shows a list of all the custom messages for the Webhooks the channel is tracked in.
* *Requires `administrator` permission in Discord*

#### !twitch preview \<twitch handle> \<webhook name>
* Shows a preview of the live notification for a given channel for the given Webhook.

</details>

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ services:
environment:
- PG_HOST=db
restart: unless-stopped
ports:
- 443:443

pg_admin:
depends_on:
Expand Down
Loading

0 comments on commit 0ddeeb8

Please sign in to comment.