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

Live Chat - Implement moderation #202

Merged
merged 5 commits into from
Oct 2, 2022

Conversation

akkadaska
Copy link
Contributor

Description

I implemented moderation of live chat, which is mentioned at issue #186.

  • add LiveChat.getItemMenu(item: ChatItemHasMenuEndpoint)
    You can call this method with ChatItemHasMenuEndpoint: chat item which has menu_endpoint member such as
    LiveChatTextMessage, and get all endpoints for moderating the chat item whose type is Promise<Menu>. You can call the
    moderation endpoint in the Menu instanse you got by following LiveChat.selectButtonItem() method.

  • add LiveChat.selectButtonItem(button: Button)
    You can call chat moderation endpoint whose type is Button (or its sub class such as MenuServiceItem) with this method.
    The modelation endpoint comes from the response of LiveChat.getItemMenu(), LiveChatTextMessage.inline_action_buttons or LiveChatAutoModMessage.moderation_buttons.

  • fix some bugs

Here is a code example of new methods: Remove all LiveChatTextMessage that you have permittion for remove.

liveChat.on('chat-update', async (chatAction: ChatAction) => {
  // only LiveChatTextMessage is filtered and assigned to liveChatTextMessage
  const menu = await liveChat.getItemMenu(liveChatTextMessage);
  const removeEndpoint = menu.items.filter((item) => {
      if (!item.is(MenuServiceItem)) {
        return false;
      }
      return item.as(MenuServiceItem).icon_type === 'DELETE';
    })[0];
  if (removeEndpoint) {
    liveChat.selectButtonItem(removeEndPoint.as(MenuServiceItem));
  }
}

Implement #186

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

@LuanRT
Copy link
Owner

LuanRT commented Sep 26, 2022

Awesome! I'll review it in a bit. Thank you for your work on this!

@akkadaska
Copy link
Contributor Author

Now LiveChat.getItemMenu(item) returns a Promise of new class ItemMenu.
We can select menu by icon_type of buttons like:

const itemMenu = await liveChat.getItemMenu(item);
itemMenu.selectItem('DELETE');

Also, we can get Menu instance by ItemMenu.menu(), which contains Button instances, and select item by Button instance like:

const itemMenu = await liveChat.getItemMenu(item);
const targetButton = itemMenu.menu().items[0];
itemMenu.selectItem(targetButton);

I think we have one more task.
LiveChatTextMessage.inline_action_buttons or LiveChatAutoModMessage.moderation_buttons also contain Button instances to call. Currently, there are no appropriate way to call such Button items.
We can select item by Button using ItemMenu.selectItem(button). However, to get ItemMenu instance, we need to call liveChat.getItemMenu(item), which causes unnecessary request to YouTube.

My only idea is that LiveChat still should have a method to select item by Button instance. Please tell me your idea.

@LuanRT
Copy link
Owner

LuanRT commented Sep 30, 2022

My only idea is that LiveChat still should have a method to select item by Button instance. Please tell me your idea.

I get what you're saying, the item menu is its own thing so that's why I suggested it to be a separate class.

A generic button selector in the LiveChat class should be fine, unless we come up with a more elaborate way to deal with those additional buttons, but I can't really think of anything at the moment.

@LuanRT LuanRT mentioned this pull request Sep 30, 2022
4 tasks
@akkadaska
Copy link
Contributor Author

Finally I added LineChat.selectButton() to select moderation buttons in LiveChatTextMessage.inline_action_buttons or LiveChatAutoModMessage.moderation_buttons. And I fixed to follow your review.

I think all tasks about #202 is completed and it's ready to merge. Please review again.

@akkadaska akkadaska requested a review from LuanRT September 30, 2022 10:08
Copy link
Owner

@LuanRT LuanRT left a comment

Choose a reason for hiding this comment

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

Great! Lgtm too!
I'll check the rest of the code to make sure we're not missing anything and then merge it ~
And again, thank you!

@LuanRT LuanRT added the enhancement New feature or request label Oct 2, 2022
@LuanRT LuanRT merged commit 2f56c15 into LuanRT:main Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants