summaryrefslogtreecommitdiff
path: root/beinc_weechat.py
diff options
context:
space:
mode:
authorSimeon Simeonov2014-08-31 13:28:22 +0200
committerSimeon Simeonov2014-08-31 13:28:22 +0200
commit472f3d3bf50b352165bc192ce5d0ffa45d81ce00 (patch)
tree56d35f027b7939284871a10a57223a768b738f51 /beinc_weechat.py
parentfa1aacfde8679551cebda346a2c45d04204441eb (diff)
Version 1.0 completed
Diffstat (limited to 'beinc_weechat.py')
-rw-r--r--beinc_weechat.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/beinc_weechat.py b/beinc_weechat.py
index 14e6eac..f878c89 100644
--- a/beinc_weechat.py
+++ b/beinc_weechat.py
@@ -79,6 +79,8 @@ class ValidHTTPSHandler(urllib2.HTTPSHandler):
79 79
80class WeechatTarget(object): 80class WeechatTarget(object):
81 """ 81 """
82 The target (destination) class
83 Each remote destination is represented as a WeechatTarget object
82 """ 84 """
83 85
84 def __init__(self, target_dict): 86 def __init__(self, target_dict):
@@ -123,48 +125,56 @@ class WeechatTarget(object):
123 @property 125 @property
124 def name(self): 126 def name(self):
125 """ 127 """
128 Target name (read-only property)
126 """ 129 """
127 return self.__name 130 return self.__name
128 131
129 @property 132 @property
130 def chans(self): 133 def chans(self):
131 """ 134 """
135 Target channel list (read-only property)
132 """ 136 """
133 return self.__chans 137 return self.__chans
134 138
135 @property 139 @property
136 def nicks(self): 140 def nicks(self):
137 """ 141 """
142 Target nick list (read-only property)
138 """ 143 """
139 return self.__nicks 144 return self.__nicks
140 145
141 @property 146 @property
142 def channel_messages_policy(self): 147 def channel_messages_policy(self):
143 """ 148 """
149 The target's channel messages policy (read-only property)
144 """ 150 """
145 return self.__chan_messages_policy 151 return self.__chan_messages_policy
146 152
147 @property 153 @property
148 def private_messages_policy(self): 154 def private_messages_policy(self):
149 """ 155 """
156 The target's private messages policy (read-only property)
150 """ 157 """
151 return self.__priv_messages_policy 158 return self.__priv_messages_policy
152 159
153 @property 160 @property
154 def notifications_policy(self): 161 def notifications_policy(self):
155 """ 162 """
163 The target's notifications policy (read-only property)
156 """ 164 """
157 return self.__notifications_policy 165 return self.__notifications_policy
158 166
159 @property 167 @property
160 def enabled(self): 168 def enabled(self):
161 """ 169 """
170 The target's enabled status (bool property)
162 """ 171 """
163 return self.__enabled 172 return self.__enabled
164 173
165 @enabled.setter 174 @enabled.setter
166 def enabled(self, value): 175 def enabled(self, value):
167 """ 176 """
177 The target's enabled status (bool property)
168 """ 178 """
169 self.__enabled = value 179 self.__enabled = value
170 180
@@ -186,6 +196,9 @@ class WeechatTarget(object):
186 196
187 def send_private_message_notification(self, values): 197 def send_private_message_notification(self, values):
188 """ 198 """
199 sends a private message notification to the represented target
200
201 values: dict pupulated by the irc msg-handler
189 """ 202 """
190 try: 203 try:
191 title_str = self.__fetch_formatted_str(self.__pm_title_template, 204 title_str = self.__fetch_formatted_str(self.__pm_title_template,
@@ -210,6 +223,9 @@ class WeechatTarget(object):
210 223
211 def send_channel_message_notification(self, values): 224 def send_channel_message_notification(self, values):
212 """ 225 """
226 sends a channel message notification to the represented target
227
228 values: dict pupulated by the irc msg-handler
213 """ 229 """
214 try: 230 try:
215 title_str = self.__fetch_formatted_str(self.__cm_title_template, 231 title_str = self.__fetch_formatted_str(self.__cm_title_template,
@@ -234,6 +250,9 @@ class WeechatTarget(object):
234 250
235 def send_notify_message_notification(self, values): 251 def send_notify_message_notification(self, values):
236 """ 252 """
253 sends a notify message notification to the represented target
254
255 values: dict pupulated by the irc msg-handler
237 """ 256 """
238 try: 257 try:
239 title_str = self.__fetch_formatted_str(self.__nm_title_template, 258 title_str = self.__fetch_formatted_str(self.__nm_title_template,
@@ -258,6 +277,10 @@ class WeechatTarget(object):
258 277
259 def send_broadcast_notification(self, message): 278 def send_broadcast_notification(self, message):
260 """ 279 """
280 sends a 'pure' broadcast / test message notification
281 to the represented target
282
283 message: a single message string
261 """ 284 """
262 try: 285 try:
263 post_values = {'title': 'BEINC broadcast', 286 post_values = {'title': 'BEINC broadcast',
@@ -277,6 +300,11 @@ class WeechatTarget(object):
277 300
278 def __fetch_formatted_str(self, template, values): 301 def __fetch_formatted_str(self, template, values):
279 """ 302 """
303 returns a formatted string by replacing the defined
304 macros in 'template' the the corresponding values from 'values'
305
306 values: dict
307 template: str
280 """ 308 """
281 template = unicode(template) 309 template = unicode(template)
282 timestamp = datetime.datetime.now().strftime(self.__timestamp_format) 310 timestamp = datetime.datetime.now().strftime(self.__timestamp_format)
@@ -384,6 +412,9 @@ def beinc_cmd_target_handler(cmd_tokens):
384 412
385 413
386def beinc_command(data, buffer_obj, args): 414def beinc_command(data, buffer_obj, args):
415 """
416 Callback function handling the Weechat's /beinc command
417 """
387 global enabled 418 global enabled
388 cmd_tokens = args.split() 419 cmd_tokens = args.split()
389 if not cmd_tokens: 420 if not cmd_tokens:
@@ -402,11 +433,15 @@ def beinc_command(data, buffer_obj, args):
402 elif cmd_tokens[0] == 'target': 433 elif cmd_tokens[0] == 'target':
403 return beinc_cmd_target_handler(cmd_tokens[1:]) 434 return beinc_cmd_target_handler(cmd_tokens[1:])
404 else: 435 else:
405 beinc_prnt('syntax: /beinc < on | off | reload | target <action> >') 436 beinc_prnt('syntax: /beinc < on | off | reload |'
437 ' broadcast <text> | target <action> >')
406 return weechat.WEECHAT_RC_OK 438 return weechat.WEECHAT_RC_OK
407 439
408 440
409def beinc_privmsg_handler(data, signal, signal_data): 441def beinc_privmsg_handler(data, signal, signal_data):
442 """
443 Callback function the *PRIVMSG* IRC messages hooked by Weechat
444 """
410 if not enabled: 445 if not enabled:
411 return weechat.WEECHAT_RC_OK 446 return weechat.WEECHAT_RC_OK
412 prvmsg_dict = weechat.info_get_hashtable('irc_message_parse', 447 prvmsg_dict = weechat.info_get_hashtable('irc_message_parse',