Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented posting Twitch Live notifications to Discord Channels #140

Merged
merged 54 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3017b24
Implemented verification for POST requests to ensure the message is f…
Jun 20, 2021
878fac0
Added basic logging to TwitchListener
Jun 20, 2021
8922e88
Added TwitchApp class to handle any data the Request handler needs to…
Jun 21, 2021
1db5ff9
Added docstring to existing methods
Jun 22, 2021
8df788a
Implemented send_webhook so that notifications get sent to their resp…
Jun 23, 2021
d590143
updated requirements.txt
Jun 23, 2021
74dbd40
updated generate_schema.py
Jun 23, 2021
d68aa96
updated gitignore
Jun 23, 2021
5c00dd8
Implemented the TwitchCog with hook creation and account adding
Jun 23, 2021
a5bbd6d
Added removetwitch and listtwitch commands
Jun 23, 2021
cae9c14
Added remove twitch hook command
Jun 23, 2021
49e3fdf
Added docstrings to command methods
Jun 23, 2021
bf5f82b
Changed CALLBACK_URL to use env var
Jun 23, 2021
ab38038
addtwitch channel now accepts a string for the custom message and als…
Jun 23, 2021
407eb49
Added user facing strings
Jun 23, 2021
a95bd35
Added command to set custom message
Jun 23, 2021
7f4fe0f
Added command to get custom message
Jun 23, 2021
33404d2
Applied YAPF formatter
Jun 23, 2021
3fac2bf
Added check to not allow webhook names to be the webhook prefix
Jun 23, 2021
a8f7b92
Moved all commands to be subcommand of `twitch`
Jun 23, 2021
7272696
Changed module name to reflect new module name in bot start
Jun 24, 2021
2bba265
Ensured consistency of use of the word channel over account when refe…
Jun 24, 2021
a8fb557
Added help and usage strings to commands
Jun 24, 2021
01996b0
Fixed an bug that caused an error when given a Twitch channel that do…
Jun 24, 2021
3345c4c
Made channel names in user strings be inline code blocks for easier r…
Jun 24, 2021
9eb15c4
Fixed missing turning list into a dict for channel info
Jun 24, 2021
879479c
Added new string for channels that are not tracked but are real channels
Jun 24, 2021
6b08e35
Added check for empty environment variables
Jun 24, 2021
62cd227
Updated some logging lines
Jun 24, 2021
8da6531
Applied YAPF formatter
Jun 24, 2021
6d4a706
Fixed typos
Jun 24, 2021
9d00bf6
Added module docstring
Jun 24, 2021
e7bb9cb
Notifications now include the custom 'go live' message
Jun 24, 2021
42849c0
Added preview command to see what a notification for a channel will l…
Jun 24, 2021
7d6429a
Applied YAPF formatting
Jun 25, 2021
b22f636
Deleted TwitchIntegrationCog
Jun 26, 2021
0269886
Merge branch 'develop' into feat/TwitchCog
Jun 26, 2021
c8b13a8
Implemented new DB accessor
Jun 27, 2021
0e4ab0f
Moved load_discord_hooks to discordUtil
Jul 5, 2021
4aef65d
Made reusable functions for loading/saving bearer tokens
Jul 5, 2021
f1449de
Updated load_tracked_channels docstring to be more consistent.
Jul 5, 2021
70d6906
Fixed some booleans to be simpler
Jul 5, 2021
41f81b9
Moved more functions to discordUtil for shared access
Jul 5, 2021
abc0367
Made global twitch api strings
Jul 5, 2021
08a8725
Fixed an issue where PyCharm doesn't recognise application as the cor…
Jul 5, 2021
764b85d
Added filter to for to avoid needing to check for membership
Jul 5, 2021
e746f31
Merge branch 'develop' into feat/TwitchCog
Fluxticks Jul 6, 2021
8369748
Exposed port 443
Jul 23, 2021
47d0b7c
Merge branch 'develop' into feat/TwitchCog
Aug 6, 2021
5caf237
Fixed an issue where if the twitch temp file did not exist it would f…
Aug 6, 2021
545c7d5
Fixed an issue caused by changing of program starting dir
Aug 6, 2021
5cfdfb8
Changed createhook command to require a name and channel as parameters
Aug 6, 2021
6dd0f9d
Updated how notifications are posted for channels so that a channel n…
Aug 8, 2021
02061cb
Updated README to include the changes to Webhooks and the tracking of…
Aug 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'develop' into feat/TwitchCog
# Conflicts:
#	secrets.template
#	src/esportsbot/bot.py
#	src/esportsbot/lib/discordUtil.py
#	src/esportsbot/user_strings.toml
  • Loading branch information
Fluxticks committed Aug 6, 2021
commit 47d0b7cb42d1b3cfe01455e737b3048150e722b4
2 changes: 1 addition & 1 deletion secrets.template
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TWITCH_CLIENT_ID=
TWITCH_CLIENT_SECRET=
TWITCH_SUB_SECRET=
TWITCH_CALLBACK=
TEMP_BEARER_FILE=bearer.wt
TEMP_BEARER_FILE=
#################

## Twitter Vars ##
Expand Down
15 changes: 2 additions & 13 deletions src/esportsbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,8 @@ def launch():
if os.getenv("ENABLE_TWITCH", "FALSE").lower() == "true":
client.load_extension("esportsbot.cogs.TwitchCog")

client.load_extension('esportsbot.cogs.VoicemasterCog')
client.load_extension('esportsbot.cogs.DefaultRoleCog')
client.load_extension('esportsbot.cogs.LogChannelCog')
client.load_extension('esportsbot.cogs.AdminCog')
client.load_extension('esportsbot.cogs.MenusCog')
client.load_extension('esportsbot.cogs.PingablesCog')
client.load_extension('esportsbot.cogs.EventCategoriesCog')
if os.getenv('ENABLE_TWITTER').lower() == 'true':
client.load_extension('esportsbot.cogs.TwitterIntegrationCog')
if os.getenv('ENABLE_TWITCH').lower() == 'true':
client.load_extension('esportsbot.cogs.TwitchCog')
if os.getenv('ENABLE_MUSIC') == 'TRUE':
client.load_extension('esportsbot.cogs.MusicCog')
if os.getenv("ENABLE_TWITTER", "FALSE").lower() == "true":
client.load_extension("esportsbot.cogs.TwitterCog")

if os.getenv("ENABLE_PINGME", "FALSE").lower() == "true":
client.load_extension("esportsbot.cogs.PingableRolesCog")
Expand Down
11 changes: 10 additions & 1 deletion src/esportsbot/lib/discordUtil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import shlex

from discord import Forbidden, RawReactionActionEvent, Message, Member, User, Client, DMChannel, GroupChannel, TextChannel
from typing import Tuple, Union
from typing import List, Tuple, Union
from . import emotes, exceptions

# Link to an empty image, to allow for an author name in embeds without providing an icon.
Expand Down Expand Up @@ -147,3 +149,10 @@ def get_webhook_by_name(current_hooks, name, guild_id, prefix_to_filter):
return hook, current_hooks.get(hook)

return None, None


def get_attempted_arg(message: str, arg_index: int) -> [str, List]:
command_args = shlex.split(message)
command_args.pop(0)
attempted_arg = command_args[arg_index]
return attempted_arg, command_args
153 changes: 96 additions & 57 deletions src/esportsbot/user_strings.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
command_error_generic = "There was an internal error while performing your command! Please contact a developer!"

[logging]
channel_set = "Logging channel has been set to <#{channel_id!s}>"
channel_set_already = "Logging channel already set to this channel"
Expand Down Expand Up @@ -27,41 +25,39 @@ default_role_removed = "Default role has been removed"
default_role_removed_log = "{author_mention} has removed the default role"

[music]
music_channel_set = "The Music Channel has been set to {channel}"
music_channel_set_log = "{author} has bound the Music Channel to {channel}"
music_channel_set = "The Music Channel has been bound to {music_channel}"
music_channel_set_log = "{author} has bound the Music Channel to {music_channel}"
music_channel_set_missing_channel = "You need to either use a # to mention the channel or paste the ID of the channel"
music_channel_set_invalid_channel = """The channel given was not valid, check the ID pasted or try using a # to mention
the channel"""
music_channel_set_not_text_channel = "You must provide a Text Channel to bind as the Music Channel"
music_channel_set_not_empty = """The channel given is not empty, if you want to clear the channel
use {prefix}setmusicchannel -c <channel>"""
use {bot_prefix}setmusicchannel -c <channel>"""

music_channel_get = "The Music Channel is currently set to {channel}"
music_channel_missing = "The Music Channel has not been set"
music_channel_get = "The Music Channel is currently set to {music_channel}"
music_channel_missing = "The Music Channel has not been bound"

music_channel_reset = "The Music Channel ({channel}) has been reset"
music_channel_reset = "The Music Channel ({music_channel}) has been reset"

music_channel_removed = "The Music Channel has been unbound from {channel}"
music_channel_removed_log = "{author} has unbound the Music Channel from {channel}"
music_channel_removed = "The Music Channel has been unbound from {music_channel}"
music_channel_removed_log = "{author} has unbound the Music Channel from {music_channel}"

bot_inactive = "I am not currently active. Start playing some songs first by joining a channel and requesting one!"
song_process_failed = "The following songs had issues while processing: \n{songs}"
song_error = "There were errors while adding some songs to the queue"

music_channel_wrong_channel = "The command `{command}` must be sent in the Music Channel"
music_channel_wrong_channel = "That command {command_option} be sent in the Music Channel"

no_connect_perms = "I need the permission `connect` to be able to join your Voice Channel"
unable_to_join = "I am unable to join your Voice Channel as either you are not in one or I am already in another one"
not_admin = "You cannot do that as you are not an administrator in this server"
no_perms_voice_channel = "{author}, I need the permission `connect` to be able to join that Voice Channel"
no_voice_voice_channel = "{author}, You must be in a voice channel to request a song"
wrong_voice_voice_channel = "{author}, I am already in another voice channel in this server"

volume_set_invalid_value = "The volume level must be between 0 and 100"
volume_set_success = "The volume has been set to {volume_level}%"

song_remove_invalid_value = "The song number must be a value in the current queue"
song_remove_valid_options = "Valid options are from `1` to `{end_index}`"
song_remove_invalid_value = "The song number must be a value in the current queue."
song_remove_valid_options = "Valid options are from {start_index} to {end_index}"
song_remove_success = "The song **{song_title}** has been removed from position **{song_position}** in the queue"

song_moved_success = "The song **{title}** has been moved from position `{from_pos}` to position `{to_pos}`"

song_pause_success = "Song Paused!"

song_resume_success = "Song Resumed!"
Expand All @@ -75,46 +71,74 @@ clear_queue_success = "Queue Cleared!"
shuffle_queue_success = "Queue Shuffled!"

[event_categories]
success_event = """✅ New event category '{event_name}' created successfully!
The event role is {event_role_mention}, and the sign-in menu is ID `{sign_in_menu_id}`, in {sign_in_channel_mention}.
success_channel = "✅ <#{channel_id!s}> is now visible to **{role_name}**!"
success_event = """✅ New event category '{event_title}' created successfuly!
The event role is {event_role_mention}, and the signin menu is ID `{signin_menu_id!s}`, in {signin_channel_mention}.

The event is currently **closed**, and invisible to your shared role, `{shared_role_name}`. Open the event when you're ready with `{command_prefix}open-event {event_name}`!
Feel free to customise the category, channels and roles, but do not synchronise the category permissions.

You can create a new channel in the category with the correct permissions by either:
- Using the `+` icon next to the category,
- Dragging your channel into the category and synchronising **just that channel**'s permissions with the category, or
- Duplicating {event_general_mention}."""
success_event_category ="✅ Event category '{event_name}' registered successfuly!"
success_event_deleted = "✅ {event_title} event category and role successfuly deleted."
success_event_role = "✅ The {event_name} event role is now **{role_name}**."
success_event_role_unregister = "✅ {event_title} event category successfuly unregistered."
success_menu = "✅ The {event_namme} event signin menu is now: {menu_url}"
success_shared_role = "✅ The shared role is now **{role_name}**."
success_event_closed = "Done!"
nothing_to_do = "Nothing to do!\n*(<#{channel_id!s}> already invisible to {shared_role}, no reactions on signin menu, no users with {event_role} role)*"

menu_title = "Sign Into {event_name}"
menu_description = "If you're attending this event, react to this message to get the '{event_role}' role, and access to secret event channels!"

react_delete_confirm = "React within 60 seconds: Are you sure you want to delete the '{event_title}' category{event_segment} and the {num_channels!s} event channels?"
react_error = "An error occurred when loading your reaction, please try the command again with a different emoji."
react_event_delete_cancel = "Event category deletion cancelled."
react_no_time = "Out of time, please try the command again."
react_start = "Please react to this message within 60 seconds, with the emoji which you would like users to react with to receive the event role:"

request_event_name = ":x: Please give the name of the event!"
request_menu_id_event_name = ":x: Please provide a menu ID and event name!"
request_menu_role_name = ":x: Please provide a menu ID, followed by a role, and the name of your event!"
request_role_id = ":x: Please provide a role to set!"

invalid_menu_id = ":x: Invalid menu ID!\nTo get a menu ID, enable discord's developer mode, right click on the menu, and click 'copy ID'"
invalid_role = ":x: Invalid role! Please give your role as either a mention or an ID."
unrecognised_event = ":x: Unrecognised event. The following events exist in this server: {events}"
unrecognised_menu_id = ":x: Unrecognised menu ID: {menu_id}"
unrecognised_role = ":x: Unrecognised role!"
invalid_signin_menu = ":x: The event signin menu must be a role menu granting the {role_name} role!"

The event is currently **closed**, and invisible to the `{shared_role_name}` role. Open the event when you're ready with `{command_prefix}open-event {event_name}`!
Feel free to create more Text Channels and Voice Channels below the ones created by the command!
"""
success_channel = "✅ <#{channel_id}> is now visible to **{role_name}**!"
channel_already_open = ":x: The {event_name} signin channel is already open! <#{channel_id!s}>"
event_exists = ":x: An event category with the name '{event_name}' already exists!"
no_events = ":x: This server doesn't have any event categories registered!"
success_event_closed = "✅ All event channels are longer visible to anyone"
success_event_deleted = "✅ {event_name} event and role successfully deleted."
delete_cancelled = "✅ {event_name} event and role will not be deleted"
unrecognised_event = ":x: Unrecognised event. The following events exist in this server: {events}"
invalid_role = ":x: Invalid role! Please give your Role as either a mention or an ID."
user_missing_perms = ":x: I am unable to perform that action as you are missing the `{permission}` permission in this server!"
bot_missing_perms = ":x: I am unable to perform that action as I may be missing one of the following permissions: `{permissions}`"
missing_arguments = ":x: There were key arguments missing in the supplied command. Try using `{prefix}help {command}` to find how to use this command"

[pingable_roles]
already_exists = ":warning: There is already a pingable role with the name `{role}` in this server"
create_success = "✅ Successfully created a poll for your pingable role"
set_poll_length = "✅ The default poll length is now set to `{poll_length} seconds`"
set_poll_threshold = "✅ The default number of votes required to create a role is now set to `{vote_threshold} votes`"
set_role_cooldown = "✅ The cooldown for pingable roles is now set to `{cooldown} seconds`"
set_poll_emoji = "✅ The emoji used to role creation polls is now set to {emoji}"
set_role_emoji = "✅ The emoji used in pingable role reaction menus is now set to {emoji}"
no_roles_given = ":x: You must mention one or more roles to use this command"
not_pingable_role = ":warning: `{role}` is not a pingable role, only pingable roles can be used with this command."
role_delete_success = "✅ The following role(s) were deleted: `{deleted_roles}`"
role_convert_success = "✅ The following role(s) were converted to pingable roles: `{converted_roles}`"
pingable_convert_success= "✅ The following role(s) were converted to normal roles: `{converted_roles}`"
invalid_role = ":x: The role or role ID is not a valid role or pingable role"
role_cooldown_updated = "✅ The ping cooldown for the role `{role}` has been set to `{seconds} seconds`"
role_emoji_updated = "✅ The emoji for the role `{role}` has been set to {emoji}"
no_pingable_roles = ":warning: There are currently no pingable roles in this server! Use the `create-role` command to invoke a poll to create one, or convert an existing role to a pingable role with the `convert-role` command"
roles_disabled = "✅ The following role(s) were disabled: `{disabled_roles}`"
roles_enabled = "✅ The following role(s) were enabled: `{enabled_roles}`"
needs_initialising = ":x: This server has not had its default settings setup! Use the `{prefix}{command}` command to setup the settings"
reserve_emoji = ":x: Sorry, the emoji `{emoji}` cannot be used as it is reserved for internal use"
default_settings_set = "✅ Default pingable settings have been applied"
missing_shared_role = ":x: I can't find the server's shared role! Was it deleted?\nPlease use the `{command_prefix}set-shared-role` command to set a new one."
no_event_categories = ":x: This server doesn't have any event categories registered!"
no_shared_role = ":x: No shared role has been set for this server! Use the {command_prefix}set-shared-role` command to set one."

no_channel_edit_perms = ":x: I don't have permission to edit the permissions in <#{channel_id!s}>!"
no_role_edit_perms = ":x: I don't have permission to assign roles!\nPlease give me the 'manage roles' permission."
role_edit_perms_bad_order = ":x: I don't have permission to unassign the **{event_role}** role!\nPlease move it below my {role_name} role."

event_category_create_reason = "Creating new event category '{event_name}' requested via {command_prefix}create-event-category command"
event_category_delete_reason = "Event category '{event_name}' deletion requested via {command_prefix}delete-event-category command"
event_channel_close_reason = "{author} closed the {event_name} event via {command_prefix}close-event command"
event_channel_open_reason = "{author} opened the {event_name} event via the {command_prefix}open-event command"

admin_channel_invisible = ["Event Channel made invisibile", "<#{channel_id!s}>"]
admin_event_category_deleted = ["Event Category Deleted", "Event name: {event_title}\nChannels deleted: {num_channels!s}"]
admin_event_category_unregistered = ["Event Category Unregistered", "Event name: {event_title}\nCategory/channels left undeleted."]
admin_event_category_updated = ["New Event Category Created", "Event name: {event_title}\nMenu ID: {menu_id!s}\nRole: <@&{role_id!s}>\n[Menu]({menu_url})"]
admin_event_closed = ["Event Closed", "Event name: {event_title}"]
admin_event_role_set = ["Event role set", "<@&{role_id}!s}>"]
admin_existing_event_registered = ["Existing Event Category Registered", "Event name: {event_title}\nMenu id: {menu_id}\nRole: <@&{role_id!s}>\n[Menu]({menu_url})"]
admin_menu_updated = ["Event signin menu updated", "Event name: {event_title}\nMenu ID: {menu_id}\nType: {menu_type}\n[Menu]({menu_url})"]
admin_role_menu_reset = ["Role menu reset", "id: {menu_id}\ntype: {menu_type}\n[Menu]({menu_url})"]
admin_role_removed = ["Event Role removed", "Users: {users!s}\n<@&{event_role_id!s}>"]
admin_shared_role_set = ["Shared role set", "<@&{role_id!s}>"]
admin_signin_visible = ["Event signin channel made visible", "<#{channel_id}>"]

[voicemaster]
success_slave_locked = "Your VM slave has been locked 🔒"
Expand Down Expand Up @@ -170,3 +194,18 @@ accounts_list = "Currently tracked accounts are: {tracked_accounts}"
account_missing_error = "Unable to {operation} {account} because there is no account with that name"
account_exists_error = "Unable to add {account} to tracked accounts because it is already tracked"

[role_reacts]
duplicate_emoji = "Cannot add the emoji {emoji} as there is already a role tied to that emoji in this reaction menu"
missing_quotes = "Unable to get title and description from message. You may be missing quotes around your title and description individually"
invalid_id = "There is no role reaction menu with the id `{given_id}`"
invalid_emoji = "The provided emoji was not a valid emoji"
disable_menu = "✅ The menu with ID `{menu_id}` has been disabled"
enable_menu = "✅ The menu with ID `{menu_id}` has been enabled"
delete_menu = "✅ The menu with ID `{menu_id}` has been deleted"

[vote_reacts]
wrong_author = ":x: You cannot perform this action, only `{author}` can do this"
needs_number = ":x: The argument required for this is a menu ID as a number. You can copy the menu ID from the footer of the menu or by copying the message ID of the menu"
invalid_id = ":warning: There is no poll with the id `{given_id}`"
disable_menu = "✅ The poll with ID `{menu_id}` has been disabled"
reset_menu = "✅ The poll with ID `{menu_id}` has had its reactions cleared"
You are viewing a condensed version of this merge commit. You can view the full changes here.