Advertisement
Jahus

Python HexChat interface example

Sep 15th, 2014
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. __module_name__ = "SomeBotName"
  2. __module_version__ = "0.1.0"
  3. __module_description__ = "Some script description"
  4.  
  5. import hexchat # HexChat IRC interface
  6.  
  7. # PRINTS TRACKING
  8. def track_trig(word, word_eol, userdata):
  9.     # STRIP word
  10.     for i in range(len(word)):
  11.         # strips the colours and the format
  12.         word[i] = hexchat.strip(word[i], -1, 3)
  13.     # in "word", the first part is the user who issued the message
  14.     user = word[0]
  15.     # the following part, word[1] is the message it self
  16.     # the first character may be the trigger (!, +, *, etc.)
  17.     trig = word[1][0]
  18.     # the next characters define the message
  19.     msg = word[1][1:]
  20.     # Let's now strip (delete the exceeding spaces)
  21.     # and then split the message into words to identify the command and its arguments
  22.     my_cmd = (word[1][1:].strip()).split(' ')
  23.     #
  24.     # Now, let's get the current context
  25.     current_context = hexchat.get_context()
  26.     # and finally, call a function depending on the trigger (@)
  27.     if (trig == "@"):
  28.         # 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 :)
  29.         user_cmd(user, current_context, my_cmd[0], my_cmd[1:])
  30.     # return EAT_NONE to let the message come to the bot logs
  31.     return hexchat.EAT_NONE
  32. # Finally, the hook that will link the function above to the action of receiving a channel message
  33. hexchat.hook_print("Channel Message", track_trig)
  34. # You can find the words "Channel Message" and many other events in HexChat menu "Settings > Text Events..."
  35.  
  36. # Now let's define the user_cmd function that will receive the user, the context, the command and its arguments
  37. # See the context as being a channel, a server, a query where the bot has been requested
  38. def user_cmd(user, context, cmd, args):
  39.     if (cmd.lower() == "bark"):
  40.         # we will make the bot bark at args
  41.         context.command("me barks at %s" % (' '.join(args)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement