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

Conversation

pajlada
Copy link
Member

@pajlada pajlada commented Nov 12, 2023

Description

  • Add support for the Create EventSub Subscription Helix API
  • Add debug command to create an eventsub subscription

This PR is expected to fail in CI - to build locally you need to have the https://github.com/pajlada/beast-websocket-client repo cloned in the same dir as your c2 repo is cloned.
I will include this as a submodule once this PR is ready to be merged in.

src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

mocks/include/mocks/Helix.hpp Show resolved Hide resolved
@pajlada pajlada force-pushed the chore/eventsub branch 2 times, most recently from d23415b to cb78caa Compare November 27, 2023 09:07
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 27. Check the log or trigger a new build to see more.

@@ -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;

});
}

void onNotification(eventsub::messages::Metadata metadata,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'onNotification' can be made static [readability-convert-member-functions-to-static]

Suggested change
void onNotification(eventsub::messages::Metadata metadata,
static void onNotification(eventsub::messages::Metadata metadata,

using namespace chatterino;
using namespace std::chrono_literals;

const QString regexHelpString("(\\w+)[.,!?;:]*?$");
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: invalid case style for global constant 'regexHelpString' [readability-identifier-naming]

Suggested change
const QString regexHelpString("(\\w+)[.,!?;:]*?$");
const QString REGEX_HELP_STRING("(\\w+)[.,!?;:]*?$");

src/providers/twitch/EventSubMessageBuilder.cpp:58:

- const QRegularExpression mentionRegex("^@" + regexHelpString);
+ const QRegularExpression mentionRegex("^@" + REGEX_HELP_STRING);

src/providers/twitch/EventSubMessageBuilder.cpp:61:

- const QRegularExpression allUsernamesMentionRegex("^" + regexHelpString);
+ const QRegularExpression allUsernamesMentionRegex("^" + REGEX_HELP_STRING);

const QString regexHelpString("(\\w+)[.,!?;:]*?$");

// matches a mention with punctuation at the end, like "@username," or "@username!!!" where capture group would return "username"
const QRegularExpression mentionRegex("^@" + regexHelpString);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: invalid case style for global constant 'mentionRegex' [readability-identifier-naming]

Suggested change
const QRegularExpression mentionRegex("^@" + regexHelpString);
const QRegularExpression MENTION_REGEX("^@" + regexHelpString);

src/providers/twitch/EventSubMessageBuilder.cpp:429:

-         auto match = mentionRegex.match(string);
+         auto match = MENTION_REGEX.match(string);

// Need to remove EmoteElement and replace with LayeredEmoteElement
auto baseEmoteElement = this->releaseBack();

std::vector<LayeredEmoteElement::Emote> layers = {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable 'layers' is not initialized [cppcoreguidelines-init-variables]

Suggested change
std::vector<LayeredEmoteElement::Emote> layers = {
std::vector<LayeredEmoteElement::Emote> layers = 0 = {

return Failure;
}

std::optional<EmotePtr> EventSubMessageBuilder::getTwitchBadge(
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'getTwitchBadge' can be made static [readability-convert-member-functions-to-static]

src/providers/twitch/EventSubMessageBuilder.hpp:63:

-     std::optional<EmotePtr> getTwitchBadge(const Badge &badge) const;
+     static std::optional<EmotePtr> getTwitchBadge(const Badge &badge) ;

src/providers/twitch/EventSubMessageBuilder.cpp:1010:

-     const Badge &badge) const
+     const Badge &badge) 

}
}

Outcome EventSubMessageBuilder::tryParseCheermote(const QString &string)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'tryParseCheermote' is within a recursive call chain [misc-no-recursion]

                                    ^
Additional context

src/providers/twitch/EventSubMessageBuilder.cpp:1232: example recursive call chain, starting from function 'tryParseCheermote'

                                    ^

src/providers/twitch/EventSubMessageBuilder.cpp:1294: Frame #1: function 'tryParseCheermote' calls function 'tryParseCheermote' here:

);
                   ^

src/providers/twitch/EventSubMessageBuilder.cpp:1294: ... which was the starting point of the recursive call chain; there may be other cycles

);
                   ^

return true;
}

void EventSubMessageBuilder::setThread(std::shared_ptr<MessageThread> thread)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'thread' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

src/providers/twitch/EventSubMessageBuilder.hpp:51:

-     void setThread(std::shared_ptr<MessageThread> thread);
+     void setThread(const std::shared_ptr<MessageThread>& thread);
Suggested change
void EventSubMessageBuilder::setThread(std::shared_ptr<MessageThread> thread)
const &

this->thread_ = std::move(thread);
}

void EventSubMessageBuilder::setParent(MessagePtr parent)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'parent' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

src/providers/twitch/EventSubMessageBuilder.hpp:52:

-     void setParent(MessagePtr parent);
+     void setParent(const MessagePtr& parent);
Suggested change
void EventSubMessageBuilder::setParent(MessagePtr parent)
const &

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

struct ChannelPointReward;
struct DeleteAction;

class EventSubMessageBuilder : MessageBuilder
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'EventSubMessageBuilder' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class EventSubMessageBuilder : MessageBuilder
      ^


void addWords();
void addTextOrEmoji(EmotePtr emote) override;
void addTextOrEmoji(const QString &value) override;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'chatterino::EventSubMessageBuilder::addTextOrEmoji' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]

    void addTextOrEmoji(const QString &value) override;
         ^
Additional context

src/providers/twitch/EventSubMessageBuilder.cpp:400: the definition seen here

void EventSubMessageBuilder::addTextOrEmoji(const QString &string_)
                             ^

src/providers/twitch/EventSubMessageBuilder.hpp:68: differing parameters are named here: ('value'), in definition: ('string_')

    void addTextOrEmoji(const QString &value) override;
         ^

Co-Authored-By: nerix <nero.9@hotmail.de>
pajlada and others added 3 commits February 25, 2024 13:39
* fix(eventsub): support all compilers and stuff

* fix: awaitable

* fix: qualify `value_to`

This is the run
@pajlada pajlada added this to the Post-2.5.0 milestone Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants