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

feat: Add initial EventSub Helix support #4962

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
33ab614
Add support for the Create EventSub Subscription Helix API
pajlada Nov 11, 2023
b8b9870
Add debug command to create an eventsub subscription
pajlada Nov 12, 2023
4982f65
Add dev changelog entry
pajlada Nov 12, 2023
30fee9a
Add eventsub class that uses the eventsub library
pajlada Nov 18, 2023
5f08890
fix: make `ChannelChatters::getUserColor` const
pajlada Nov 18, 2023
b7d9a48
fix: make `TwitchChannel::cheerEmote` const
pajlada Nov 18, 2023
9399d4b
clang-tidy: allow MOCK_METHOD function name
pajlada Nov 18, 2023
41214cd
Add license for date.h
pajlada Nov 18, 2023
d183f11
Add support for `channel.ban v1` to replace pubsub
pajlada Nov 18, 2023
f7b12a9
Add eventsub logging category
pajlada Nov 19, 2023
8bb9be0
update for new eventsub lib version
pajlada Nov 19, 2023
da79753
Fix date.h license link
pajlada Nov 21, 2023
9bf5cfe
fix for application changes
pajlada Jan 26, 2024
2db096d
add eventsub over chat shitty code & proper submodule
pajlada Jan 26, 2024
71bd1ed
fix channel.chat.message subscription version
pajlada Jan 26, 2024
23d4fb2
update `twitch-eventsub-ws` version
pajlada Jan 26, 2024
aa16d87
fix: use header-only boost
pajlada Jan 28, 2024
5616dc4
Merge remote-tracking branch 'origin/master' into chore/eventsub
pajlada Feb 25, 2024
08d8d26
nit: remove const in return value of ChannelChatters::getUserColor
pajlada Feb 25, 2024
7d2e817
clang-tidy: unused ctx param
pajlada Feb 25, 2024
b7a3215
remove todo comment
pajlada Feb 25, 2024
8ec40f9
Move TwitchEmoteOccurrence to TwitchCommon.hpp
pajlada Feb 25, 2024
38560ba
Enable SSL certificate verification
pajlada Feb 25, 2024
0e9c193
fix(eventsub): compilation issues (#5212)
Nerixyz Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CheckOptions:
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: ^TEST$
value: ^(TEST|MOCK_METHOD)$

- key: readability-identifier-naming.MemberCase
value: camelBack
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@
[submodule "tools/crash-handler"]
path = tools/crash-handler
url = https://github.com/Chatterino/crash-handler
[submodule "lib/twitch-eventsub-ws"]
path = lib/twitch-eventsub-ws
url = https://github.com/Chatterino/twitch-eventsub-ws
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
- Dev: Refactor `common/Credentials`. (#4979)
- Dev: Refactor chat logger. (#5058)
- Dev: Refactor Twitch PubSub client. (#5059)
- Dev: Add EventSub Helix support. (#4962)
- Dev: Changed lifetime of context menus. (#4924)
- Dev: Renamed `tools` directory to `scripts`. (#5035)
- Dev: Refactor `ChannelView`, removing a bunch of clang-tidy warnings. (#4926)
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ endif ()
find_package(Sanitizers QUIET)

# Find boost on the system
find_package(Boost REQUIRED OPTIONAL_COMPONENTS headers)
find_package(Boost REQUIRED OPTIONAL_COMPONENTS headers json)

# Find OpenSSL on the system
find_package(OpenSSL REQUIRED)
Expand Down Expand Up @@ -204,6 +204,8 @@ else()
add_subdirectory("${CMAKE_SOURCE_DIR}/lib/settings" EXCLUDE_FROM_ALL)
endif()

add_subdirectory("${CMAKE_SOURCE_DIR}/lib/twitch-eventsub-ws" EXCLUDE_FROM_ALL)

if (CHATTERINO_PLUGINS)
set(LUA_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/lua/src")
add_subdirectory(lib/lua)
Expand Down
1 change: 1 addition & 0 deletions lib/twitch-eventsub-ws
Submodule twitch-eventsub-ws added at 94c62d
9 changes: 9 additions & 0 deletions mocks/include/mocks/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@ class Helix : public IHelix
(FailureCallback<HelixSendShoutoutError, QString> failureCallback)),
(override));

MOCK_METHOD(void, createEventSubSubscription,
pajlada marked this conversation as resolved.
Show resolved Hide resolved
(const QString &type, const QString &version,
const QString &sessionID, const QJsonObject &condition,
ResultCallback<HelixCreateEventSubSubscriptionResponse>
successCallback,
(FailureCallback<HelixCreateEventSubSubscriptionError, QString>
failureCallback)),
(override));

MOCK_METHOD(void, update, (QString clientId, QString oauthToken),
(override));

Expand Down
30 changes: 30 additions & 0 deletions resources/licenses/howard-hinnant-date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
The MIT License (MIT)

Copyright (c) 2015, 2016, 2017 Howard Hinnant
Copyright (c) 2016 Adrian Colomitchi
Copyright (c) 2017 Florian Dang
Copyright (c) 2017 Paul Thompson
Copyright (c) 2018, 2019 Tomasz Kamiński
Copyright (c) 2019 Jiangang Zhuang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Our apologies. When the previous paragraph was written, lowercase had not yet
been invented (that would involve another several millennia of evolution).
We did not mean to shout.
11 changes: 11 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ set(SOURCE_FILES

providers/twitch/ChannelPointReward.cpp
providers/twitch/ChannelPointReward.hpp
providers/twitch/EventSub.cpp
providers/twitch/EventSub.hpp
providers/twitch/EventSubMessageBuilder.cpp
providers/twitch/EventSubMessageBuilder.hpp
providers/twitch/IrcMessageHandler.cpp
providers/twitch/IrcMessageHandler.hpp
providers/twitch/PubSubActions.cpp
Expand Down Expand Up @@ -764,7 +768,9 @@ target_link_libraries(${LIBRARY_PROJECT}
RapidJSON::RapidJSON
LRUCache
MagicEnum
twitch-eventsub-ws
)

if (CHATTERINO_PLUGINS)
target_link_libraries(${LIBRARY_PROJECT} PUBLIC lua)
endif()
Expand Down Expand Up @@ -814,6 +820,11 @@ if (BUILD_APP)

target_link_libraries(${EXECUTABLE_PROJECT} PUBLIC ${LIBRARY_PROJECT})

target_link_libraries(${EXECUTABLE_PROJECT}
PUBLIC
twitch-eventsub-ws
)

set_target_directory_hierarchy(${EXECUTABLE_PROJECT})

if (WIN32)
Expand Down
2 changes: 1 addition & 1 deletion src/common/ChannelChatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ size_t ChannelChatters::colorsSize() const
return size;
}

const QColor ChannelChatters::getUserColor(const QString &user)
const QColor ChannelChatters::getUserColor(const QString &user) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: return type 'const QColor' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]

Suggested change
const QColor ChannelChatters::getUserColor(const QString &user) const
QColor ChannelChatters::getUserColor(const QString &user) const

src/common/ChannelChatters.hpp:26:

-     const QColor getUserColor(const QString &user) const;
+     QColor getUserColor(const QString &user) const;

{
const auto chatterColors = this->chatterColors_.access();

Expand Down
2 changes: 1 addition & 1 deletion src/common/ChannelChatters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ChannelChatters
void addRecentChatter(const QString &user);
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
const QColor getUserColor(const QString &user);
const QColor getUserColor(const QString &user) const;
void setUserColor(const QString &user, const QColor &color);
void updateOnlineChatters(const std::unordered_set<QString> &usernames);

Expand Down
2 changes: 2 additions & 0 deletions src/common/QLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Q_LOGGING_CATEGORY(chatterinoStreamlink, "chatterino.streamlink", logThreshold);
Q_LOGGING_CATEGORY(chatterinoTheme, "chatterino.theme", logThreshold);
Q_LOGGING_CATEGORY(chatterinoTokenizer, "chatterino.tokenizer", logThreshold);
Q_LOGGING_CATEGORY(chatterinoTwitch, "chatterino.twitch", logThreshold);
Q_LOGGING_CATEGORY(chatterinoTwitchEventSub, "chatterino.twitch.eventsub",
logThreshold);
Q_LOGGING_CATEGORY(chatterinoTwitchLiveController,
"chatterino.twitch.livecontroller", logThreshold);
Q_LOGGING_CATEGORY(chatterinoUpdate, "chatterino.update", logThreshold);
Expand Down
1 change: 1 addition & 0 deletions src/common/QLogging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoStreamlink);
Q_DECLARE_LOGGING_CATEGORY(chatterinoTheme);
Q_DECLARE_LOGGING_CATEGORY(chatterinoTokenizer);
Q_DECLARE_LOGGING_CATEGORY(chatterinoTwitch);
Q_DECLARE_LOGGING_CATEGORY(chatterinoTwitchEventSub);
Q_DECLARE_LOGGING_CATEGORY(chatterinoTwitchLiveController);
Q_DECLARE_LOGGING_CATEGORY(chatterinoUpdate);
Q_DECLARE_LOGGING_CATEGORY(chatterinoWebsocket);
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ void CommandController::initialize(Settings &, const Paths &paths)
this->registerCommand("/debug-force-image-unload",
&commands::forceImageUnload);

this->registerCommand("/debug-eventsub", &commands::debugEventSub);

this->registerCommand("/shield", &commands::shieldModeOn);
this->registerCommand("/shieldoff", &commands::shieldModeOff);

Expand Down
16 changes: 16 additions & 0 deletions src/controllers/commands/builtin/chatterino/Debugging.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#include "controllers/commands/builtin/chatterino/Debugging.hpp"

#include "Application.hpp"
#include "common/Channel.hpp"
#include "common/Env.hpp"
#include "common/Literals.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "messages/Image.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/EventSub.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Theme.hpp"
#include "util/PostToThread.hpp"

Expand Down Expand Up @@ -134,4 +141,13 @@ QString forceImageUnload(const CommandContext &ctx)
return "";
}

QString debugEventSub(const CommandContext &ctx)
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
static EventSub eventSub;

eventSub.start();

return "";
}

} // namespace chatterino::commands
2 changes: 2 additions & 0 deletions src/controllers/commands/builtin/chatterino/Debugging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ QString forceImageGarbageCollection(const CommandContext &ctx);

QString forceImageUnload(const CommandContext &ctx);

QString debugEventSub(const CommandContext &ctx);

} // namespace chatterino::commands