diff options
| author | Simeon Simeonov | 2012-11-13 15:40:27 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2012-11-13 15:40:27 +0100 |
| commit | 5c2becae337ea7e2bcebec2912e4626d853b16aa (patch) | |
| tree | 8176d6f36f1c9d758670bdd0c0752167af775ba7 /bosd.py | |
| parent | b1b484a0b93a5651da7d1ca20e77f70089b215bb (diff) | |
All working with sqlite
Diffstat (limited to 'bosd.py')
| -rw-r--r-- | bosd.py | 92 |
1 files changed, 92 insertions, 0 deletions
| @@ -0,0 +1,92 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | # -*- coding: utf-8 -*- | ||
| 3 | |||
| 4 | import socket | ||
| 5 | import weechat | ||
| 6 | |||
| 7 | #### CONFIG #### | ||
| 8 | enabled = True | ||
| 9 | |||
| 10 | notify_channels = [ | ||
| 11 | "RedpillLinpro.#python", | ||
| 12 | "Exile.#hin", | ||
| 13 | "RedpillLinpro.#adult", | ||
| 14 | "Exile.#pichove" | ||
| 15 | ] | ||
| 16 | |||
| 17 | connections = [ {'sbosdd_ip': '127.0.0.1', | ||
| 18 | 'sbosdd_port': 9999}, | ||
| 19 | # {'sbosdd_ip': "10.0.0.2", | ||
| 20 | # 'sbosdd_port': 9999} | ||
| 21 | ] | ||
| 22 | ################ | ||
| 23 | |||
| 24 | def bosd_send_xosd_message(message): | ||
| 25 | for conn in connections: | ||
| 26 | try: | ||
| 27 | #weechat.prnt("", message) | ||
| 28 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| 29 | s.connect((conn['sbosdd_ip'], conn['sbosdd_port'])) | ||
| 30 | s.send(message) | ||
| 31 | s.close() | ||
| 32 | except: | ||
| 33 | continue | ||
| 34 | |||
| 35 | return True | ||
| 36 | |||
| 37 | |||
| 38 | def bosd_command(data, buffer, args): | ||
| 39 | global enabled | ||
| 40 | if args == 'on': | ||
| 41 | enabled = True | ||
| 42 | weechat.prnt(weechat.current_buffer(), "bosd on") | ||
| 43 | elif args == 'off': | ||
| 44 | enabled = False | ||
| 45 | weechat.prnt(weechat.current_buffer(), "bosd off") | ||
| 46 | else: | ||
| 47 | bosd_send_xosd_message(args) | ||
| 48 | |||
| 49 | return weechat.WEECHAT_RC_OK | ||
| 50 | |||
| 51 | |||
| 52 | def bosd_privmsg_handler(data, signal, signal_data): | ||
| 53 | if not enabled: | ||
| 54 | return weechat.WEECHAT_RC_OK | ||
| 55 | |||
| 56 | prvmsg_dict = weechat.info_get_hashtable("irc_message_parse", | ||
| 57 | { "message": signal_data }) | ||
| 58 | |||
| 59 | |||
| 60 | server = signal.split(",")[0] | ||
| 61 | |||
| 62 | # channel = signal_data.split(":")[-1] | ||
| 63 | # my_nick = weechat.info_get("irc_nick_from_host", signal_data) | ||
| 64 | |||
| 65 | my_nick = weechat.info_get("irc_nick", server) | ||
| 66 | channel = prvmsg_dict['arguments'].split(":")[0].strip() | ||
| 67 | nick = prvmsg_dict['nick'] | ||
| 68 | message = ':'.join(prvmsg_dict['arguments'].split(':')[1:]).strip() | ||
| 69 | |||
| 70 | if (my_nick in message) or ('{0}.{1}'.format(server,channel) in notify_channels): | ||
| 71 | template_msg = '{0} @ {1} - {2}: {3}'.format(channel, | ||
| 72 | server, | ||
| 73 | nick, | ||
| 74 | message) | ||
| 75 | bosd_send_xosd_message(template_msg) | ||
| 76 | |||
| 77 | if my_nick in channel: | ||
| 78 | template_msg = '{0} @ {1}: {2}'.format(nick, server, message) | ||
| 79 | bosd_send_xosd_message(template_msg) | ||
| 80 | |||
| 81 | #my_str = "%s - %s - %s - %s" % (my_nick, server, channel, message) | ||
| 82 | #weechat.prnt("", my_str) | ||
| 83 | |||
| 84 | return weechat.WEECHAT_RC_OK | ||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | weechat.register('bosd', 'Simeon Simeonov', '1.0', 'GPL3', 'Socket notification script', "", "") | ||
| 89 | weechat.hook_command("bosd", "bosd on off toggle", "<on | off>", "description...", "None", "bosd_command", "") | ||
| 90 | weechat.hook_signal("*,irc_in2_privmsg", "bosd_privmsg_handler", "") | ||
| 91 | |||
| 92 | weechat.prnt("", "bosd initiated!") | ||
