GithubHelp home page GithubHelp logo

Need to fix get_username() about mmpy_bot HOT 6 CLOSED

attzonko avatar attzonko commented on August 30, 2024
Need to fix get_username()

from mmpy_bot.

Comments (6)

attzonko avatar attzonko commented on August 30, 2024 2

Well originally, before I made the changes, the code always just returned the sender name regardless of user_id given or not. So I will go ahead and merge the change in to at least restore the way it worked when user_id is None. Thanks for digging into the details of how the username override stuff actually works.

from mmpy_bot.

seLain avatar seLain commented on August 30, 2024

There is a chance that username(user_id) != sender_name .

When sending post through webhook, there is a parameter username which can overrides the username the message posts as if EnablePostUsernameOverride is set to true.

Example 1 : EnablePostUsernameOverride = false

For example, if we send a hello post through webhook with username = "mockname" when EnablePostUsernameOverride = false (default), the post will look like this :

{'event': 'posted', 'data': {'channel_display_name': 'Off-Topic', 'channel_name': 'off-topic', 'channel_type': 'O', 'post': {'id': 'hu8s8abo3fy69xt7nwfm1fq3ka', 'create_at': 1531852142221, 'update_at': 1531852142221, 'edit_at': 0, 'delete_at': 0, 'is_pinned': False, 'user_id': 'ta7a1ceamt8kiegt445emo6e5h', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'root_id': '', 'parent_id': '', 'original_id': '', 'message': 'hello', 'type': '', 'props': {'from_webhook': 'true'}, 'hashtags': '', 'pending_post_id': ''}, 'sender_name': 'amy', 'team_id': 'au64gza3iint3r31e7ewbrrasw'}, 'broadcast': {'omit_users': None, 'user_id': '', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'team_id': ''}, 'seq': 2, 'message_type': '?'}

The name displayed on MM channel will be amy [bot].

Example 2 : EnablePostUsernameOverride = true

And if it is sent when EnablePostUsernameOverride = true, the post will be :

{'event': 'posted', 'data': {'channel_display_name': 'Off-Topic', 'channel_name': 'off-topic', 'channel_type': 'O', 'post': {'id': '45o6whbrp3no5djmg5iabm14ky', 'create_at': 1531879612382, 'update_at': 1531879612382, 'edit_at': 0, 'delete_at': 0, 'is_pinned': False, 'user_id': 'ta7a1ceamt8kiegt445emo6e5h', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'root_id': '', 'parent_id': '', 'original_id': '', 'message': 'hello', 'type': '', 'props': {'from_webhook': 'true', 'override_username': 'mockname'}, 'hashtags': '', 'pending_post_id': ''}, 'sender_name': 'mockname', 'team_id': 'au64gza3iint3r31e7ewbrrasw'}, 'broadcast': {'omit_users': None, 'user_id': '', 'channel_id': '4fgt3n51f7ftpff91gk1iy1zow', 'team_id': ''}, 'seq': 2, 'message_type': '?'}

The name displayed on MM channel will be mockname [bot].

Diff

Both posts are sent by the same user account, so the user_id is also the same. But example2 has sender_name overridden, and an additional override_username.

So I think the current code is fine since it returns the actual username by user_id.

def get_username(self, user_id=None):
    return self.get_user_info('username', user_id)

If developers need to get sender_name or override_username, maybe we should consider expose them as public methods ?

from mmpy_bot.

attzonko avatar attzonko commented on August 30, 2024

When the user_id paramter is provided to Message.get_username(user_id) I totally agree with you we should lookup the username by the user_id. However, we should try to think about the intent of calling Message.get_username() when no parameter is given. In that case in my opinion the most logical intent seems to be to get the username seen in the channel for that message, regardless of the fact that it could be overridden. Does that make sense @seLain?

We could expose both sender_name and override_username if you think those are also needed.

from mmpy_bot.

seLain avatar seLain commented on August 30, 2024

Well, I just thought originally get_username would return the actual username. So I tried to make clear if username(user_id) != sender_name in some cases.

If the intention is to get the username seen in the channel for that message when user_id is given none, I am ok with the change :)

from mmpy_bot.

at4446 avatar at4446 commented on August 30, 2024

@attzonko I am trying to use get_user_info(USER_ID) but I want it to get the USER_ID dynamically. is there any method to use for this purpose? basically I cannot hard code the USER_ID and I want the script to pull out the user ID of the person talking to the BOT.

from mmpy_bot.

attzonko avatar attzonko commented on August 30, 2024

@attzonko I am trying to use get_user_info(USER_ID) but I want it to get the USER_ID dynamically. is there any method to use for this purpose? basically I cannot hard code the USER_ID and I want the script to pull out the user ID of the person talking to the BOT.

I think you want to use just message.get_username()

from mmpy_bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.