Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __module_name__ = "SomeBotName"
- __module_version__ = "0.1.0"
- __module_description__ = "Some script description"
- import hexchat # HexChat IRC interface
- # PRINTS TRACKING
- def track_trig(word, word_eol, userdata):
- # STRIP word
- for i in range(len(word)):
- # strips the colours and the format
- word[i] = hexchat.strip(word[i], -1, 3)
- # in "word", the first part is the user who issued the message
- user = word[0]
- # the following part, word[1] is the message it self
- # the first character may be the trigger (!, +, *, etc.)
- trig = word[1][0]
- # the next characters define the message
- msg = word[1][1:]
- # Let's now strip (delete the exceeding spaces)
- # and then split the message into words to identify the command and its arguments
- my_cmd = (word[1][1:].strip()).split(' ')
- #
- # Now, let's get the current context
- current_context = hexchat.get_context()
- # and finally, call a function depending on the trigger (@)
- if (trig == "@"):
- # we ask the user_cmd function with args user, current_context, my_cmd[0] being the first word got after the trigger, then the command. And my_cmd[1:], the following, would be the arguments :)
- user_cmd(user, current_context, my_cmd[0], my_cmd[1:])
- # return EAT_NONE to let the message come to the bot logs
- return hexchat.EAT_NONE
- # Finally, the hook that will link the function above to the action of receiving a channel message
- hexchat.hook_print("Channel Message", track_trig)
- # You can find the words "Channel Message" and many other events in HexChat menu "Settings > Text Events..."
- # Now let's define the user_cmd function that will receive the user, the context, the command and its arguments
- # See the context as being a channel, a server, a query where the bot has been requested
- def user_cmd(user, context, cmd, args):
- if (cmd.lower() == "bark"):
- # we will make the bot bark at args
- context.command("me barks at %s" % (' '.join(args)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement