Skip to content

feat: allow timeout-related commands to be used in multiple channels - #5402

Merged
pajlada merged 20 commits into
masterfrom
feat/multi-channel-ban
Jun 16, 2024
Merged

pajlada merged 20 commits into
masterfrom
feat/multi-channel-ban

Conversation

@pajlada

@pajlada pajlada commented May 18, 2024 •

Copy link
Copy Markdown
Member

This PR changes the behaviour of the following commands:

  • /ban
  • /timeout
  • /untimeout
  • /unban

All of those commands now accept one or more --channel parameters to override which channel the action should take place in.
The --channel parameter accepts a channel ID or channel name with the same syntax as the other "user targets" do (e.g. id:11148817 or pajlada)

examples
Ban user in the chat you're typing in:
/ban weeb123

Ban user in the chat you're typing in, with a reason specified:
/ban weeb123 the ban reason

Ban user in a separate chat, with a reason specified:
/ban --channel pajlada weeb123 the ban reason

Ban user in two separate chats, with a reason specified:
/ban --channel pajlada --channel id:117166826 weeb123 the ban reason

Timeout user in the chat you're typing in:
/timeout weeb123

Timeout user in the chat you're typing in, with a reason specified:
/timeout weeb123 10m the timeout reason

Timeout user in a separate chat, with a reason specified:
/timeout --channel pajlada weeb123 10m the timeout reason

Timeout user in two separate chats, with a reason specified:
/timeout --channel pajlada --channel id:117166826 weeb123 10m the timeout reason

Unban user in the chat you're typing in:
/unban weeb123

Unban user in a separate chat:
/unban --channel pajlada weeb123

Unban user in two separate chats:
/unban --channel pajlada --channel id:117166826 weeb123

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

"from chatting. Reason is optional and will be shown to the target "
"user and other moderators. Use \"/unban\" to remove a ban.";
if (words.size() < 2)
std::vector<PerformChannelAction> actions;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Suggested change
std::vector<PerformChannelAction> actions;
std::vector<PerformChannelAction> actions = 0;

@pajlada
pajlada force-pushed the feat/multi-channel-ban branch from b79ed44 to 2ecb541 Compare May 19, 2024 12:24

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
@@ -1,5 +1,7 @@
#pragma once

#include "expected.hpp"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: 'expected.hpp' file not found [clang-diagnostic-error]

#include "expected.hpp"
         ^

Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp Outdated

} // namespace

TEST(Commands, parseBanCommand)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "TEST" is directly included [misc-include-cleaner]

tests/src/Commands.cpp:8:

+ #include <gtest/gtest.h>

Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp Outdated
};
auto oActions = commands::parseChannelAction(ctx, "/ban", "usage", false);

ASSERT_TRUE(oActions.has_value()) << oActions.error();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "ASSERT_TRUE" is directly included [misc-include-cleaner]

    ASSERT_TRUE(oActions.has_value()) << oActions.error();
    ^

Comment thread tests/src/Commands.cpp Outdated

ASSERT_TRUE(oActions.has_value()) << oActions.error();
auto actions = *oActions;
ASSERT_EQ(actions.size(), 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "ASSERT_EQ" is directly included [misc-include-cleaner]

    ASSERT_EQ(actions.size(), 1);
    ^

@jupjohn

jupjohn commented May 21, 2024

Copy link
Copy Markdown
Contributor

In your example, you're using raw IDs but in other commands IDs have to be prefixed with id:. Could the same behaviour be used here to support both channel names & IDs? Keeps it consistent.

Also, are ---prefixed arguments used anywhere else? I don't have a better idea, but they feel very programmer-y which might feel weird to users.

@pajlada

pajlada commented May 21, 2024

Copy link
Copy Markdown
Member Author

-- prefixes are used in /openurl - I'm ok with them being a bit programmery since this use case is a bit programmery

I'm fine with --channel accepting the same type of input, e.g. 11148817 or pajlada

@pajlada pajlada changed the title feat: allow /ban to be used in multiple channels at once feat: allow timeout-related commands to be used in multiple channels May 21, 2024

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
namespace chatterino::commands {

QString sendBan(const CommandContext &ctx)
nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "nonstd::expected_lite::expected" is directly included [misc-include-cleaner]

src/controllers/commands/builtin/twitch/Ban.cpp:7:

- #include "providers/twitch/api/Helix.hpp"
+ #include "nonstd/expected.hpp"
+ #include "providers/twitch/api/Helix.hpp"

namespace chatterino::commands {

QString sendBan(const CommandContext &ctx)
nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

src/controllers/commands/builtin/twitch/Ban.cpp:14:

+ #include <vector>

{
return "";
// A ban action must be performed with a channel as a context
return nonstd::make_unexpected(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "nonstd::expected_lite::make_unexpected" is directly included [misc-include-cleaner]

        return nonstd::make_unexpected(
                       ^

}

if (twitchChannel == nullptr)
QCommandLineParser parser;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "QCommandLineParser" is directly included [misc-include-cleaner]

src/controllers/commands/builtin/twitch/Ban.cpp:14:

+ #include <qcommandlineparser.h>

Comment thread tests/src/Commands.cpp Outdated

} // namespace

TEST(Commands, parseBanCommand)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "TEST" is directly included [misc-include-cleaner]

tests/src/Commands.cpp:8:

+ #include <gtest/gtest.h>

Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp Outdated
};
auto oActions = commands::parseChannelAction(ctx, "/ban", "usage", false);

ASSERT_TRUE(oActions.has_value()) << oActions.error();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "ASSERT_TRUE" is directly included [misc-include-cleaner]

    ASSERT_TRUE(oActions.has_value()) << oActions.error();
    ^

Comment thread tests/src/Commands.cpp Outdated

ASSERT_TRUE(oActions.has_value()) << oActions.error();
auto actions = *oActions;
ASSERT_EQ(actions.size(), 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "ASSERT_EQ" is directly included [misc-include-cleaner]

    ASSERT_EQ(actions.size(), 1);
    ^

pajlada added 4 commits June 2, 2024 11:50
example:
`/ban --channel 11148817 --channel 117166826 forsen game complainer`

this would ban forsen with the reason `game complainer` in the two
listed channels
@pajlada
pajlada force-pushed the feat/multi-channel-ban branch from 520e12f to e03c5e8 Compare June 2, 2024 09:50

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp Outdated
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp Outdated
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp Outdated
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp Outdated
Comment thread tests/src/Commands.cpp Outdated
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp Outdated
Comment thread tests/src/Commands.cpp Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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 29. Check the log or trigger a new build to see more.

Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/common/ChannelAction.hpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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 29. Check the log or trigger a new build to see more.

Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/builtin/twitch/Ban.cpp
Comment thread src/controllers/commands/common/ChannelAction.hpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
Comment thread tests/src/Commands.cpp
@pajlada
pajlada marked this pull request as ready for review June 2, 2024 14:31

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread mocks/include/mocks/EmptyApplication.hpp
Comment thread mocks/include/mocks/EmptyApplication.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/Logging.hpp
Comment thread mocks/include/mocks/Logging.hpp Outdated
Comment thread mocks/include/mocks/Logging.hpp
Comment thread src/singletons/Logging.hpp
Comment thread tests/src/Commands.cpp

@pajlada pajlada left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

image

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread mocks/include/mocks/EmptyApplication.hpp
Comment thread mocks/include/mocks/EmptyApplication.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
Comment thread mocks/include/mocks/LinkResolver.hpp
LinkResolver() = default;
~LinkResolver() override = default;

MOCK_METHOD(void, resolve, (LinkInfo * info), (override));

Copy link
Copy Markdown
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 function 'MOCK_METHOD' [readability-identifier-naming]

Suggested change
MOCK_METHOD(void, resolve, (LinkInfo * info), (override));
mockMethod(void, resolve, (LinkInfo * info), (override));


namespace chatterino::mock {

class Logging : public ILogging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: class 'Logging' 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 Logging : public ILogging
      ^

Logging() = default;
~Logging() override = default;

MOCK_METHOD(void, addMessage,

Copy link
Copy Markdown
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 function 'MOCK_METHOD' [readability-identifier-naming]

Suggested change
MOCK_METHOD(void, addMessage,
mockMethod(void, addMessage,

(override));
};

class EmptyLogging : public ILogging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: class 'EmptyLogging' 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 EmptyLogging : public ILogging
      ^

class LoggingChannel;

class Logging
class ILogging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: class 'ILogging' 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 ILogging
      ^

Comment thread tests/src/Commands.cpp

using namespace chatterino;

using ::testing::_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]

using ::testing::_;
                 ^

@pajlada
pajlada merged commit 9b31246 into master Jun 16, 2024
@pajlada
pajlada deleted the feat/multi-channel-ban branch June 16, 2024 10:22
babicekmarek pushed a commit to babicekmarek/streamally-chatterino that referenced this pull request Sep 14, 2026
…hatterino#5402)

This changes the behaviour of the following commands:
 - `/ban`
 - `/timeout`
 - `/untimeout`
 - `/unban`

All of those commands now accept one or more `--channel` parameters to override which channel the action should take place in.
The `--channel` parameter accepts a channel ID or channel name with the same syntax as the other "user targets" do (e.g. `id:11148817` or `pajlada`)

examples
Ban user in the chat you're typing in:  
`/ban weeb123`

Ban user in the chat you're typing in, with a reason specified:  
`/ban weeb123 the ban reason`

Ban user in a separate chat, with a reason specified:  
`/ban --channel pajlada weeb123 the ban reason`

Ban user in two separate chats, with a reason specified:  
`/ban --channel pajlada --channel id:117166826 weeb123 the ban reason`


Timeout user in the chat you're typing in:  
`/timeout weeb123`

Timeout user in the chat you're typing in, with a reason specified:  
`/timeout weeb123 10m the timeout reason`

Timeout user in a separate chat, with a reason specified:  
`/timeout --channel pajlada weeb123 10m the timeout reason`

Timeout user in two separate chats, with a reason specified:  
`/timeout --channel pajlada --channel id:117166826 weeb123 10m the timeout reason`


Unban user in the chat you're typing in:  
`/unban weeb123`

Unban user in a separate chat:  
`/unban --channel pajlada weeb123`

Unban user in two separate chats:  
`/unban --channel pajlada --channel id:117166826 weeb123`
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.

2 participants