- Location:
- /trunk
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/amazonbot/amazonbot.py
r20 r28 3 3 4 4 __version__ = '$Revision$' 5 __author__ = 'Atzm WATANABE < sitosito@p.chan.ne.jp>'5 __author__ = 'Atzm WATANABE <atzm@atzm.org>' 6 6 __date__ = '$Date$' 7 __copyright__ = 'Copyright(C) 2006 Atzm WATANABE, all rights reserved.'7 __copyright__ = 'Copyright(C) 2006-2007 Atzm WATANABE, all rights reserved.' 8 8 __license__ = 'Python' 9 9 10 10 import re 11 import string 11 12 import sys 12 13 import time … … 147 148 return method(c, e, to, words[1:]) # words[0] == command name 148 149 150 self.message_action(msg, c, e, to) 151 149 152 # silence 150 153 self.silence(msg, c, e, to) … … 217 220 def get_prev_time(self): 218 221 return self._prev_time 222 223 def message_action(self, msg, c, e, to): 224 for i in xrange(100): 225 action = 'action%d' % i 226 if not config.has_section(action): 227 break 228 229 c_stime = config.get(action, 'start_time') 230 c_etime = config.get(action, 'end_time') 231 232 try: 233 if c_stime and c_etime: 234 now = time.time() 235 [now_y, now_m, now_d] = time.localtime(now)[:3] 236 237 stime = '%04d/%02d/%02d %s' % (now_y, now_m, now_d, c_stime) 238 etime = '%04d/%02d/%02d %s' % (now_y, now_m, now_d, c_etime) 239 stime = time.mktime(time.strptime(stime, '%Y/%m/%d %H:%M')) 240 etime = time.mktime(time.strptime(etime, '%Y/%m/%d %H:%M')) 241 242 if not ((stime <= now) and (now <= etime)): 243 _debug('Out of time: %s - %s' % (c_stime, c_etime)) 244 continue 245 except: 246 _debug('Invalid time: %s - %s' % (str(c_stime), str(c_etime))) 247 continue 248 249 pattern = unicoding(config.get(action, 'input_pattern')) 250 match = None 251 try: 252 match = re.search(pattern, msg) 253 except: 254 _debug('Invalid regexp: %s', pattern) 255 continue 256 257 if not match: 258 continue 259 260 act = config.get(action, 'action') 261 fmt = config.get(action, 'message') 262 try: 263 _from = nm_to_n(e.source()) 264 message = ununicoding(fmt % _from) 265 266 if not message: 267 _debug('No message specified') 268 continue 269 270 if not act: 271 c.notice(to, message) 272 continue 273 274 method = getattr(self, 'onact_%s' % act, lambda *arg: False) 275 method(message, c, e, to) 276 277 except: 278 _debug('Action failed: %s (%s)' % (str(act), str(fmt))) 279 280 return True 219 281 220 282 class AmazonBot(AmazonBotBase): … … 244 306 return 'AmazonBot by %s, based on python-irclib' % __author__ 245 307 308 def onmsg_reload(self, c, e, to, args): 309 """Syntax: !reload 310 """ 311 _debug('in reload command: %s', str(args)) 312 config.read() 313 c.notice(to, 'reloaded config') 314 return True 315 316 def onmsg_lt(self, c, e, to, args): return self.onmsg_localtime(c, e, to, args) 317 def onmsg_localtime(self, c, e, to, args): 318 """Syntax: !localtime <unix time> 319 """ 320 _debug('in localtime command: %s', str(args)) 321 322 _from = nm_to_n(e.source()) 323 try: 324 sec = float(args[0]) 325 c.notice(_from, time.strftime('%b %d %T', time.localtime(sec))) 326 except ValueError, e: 327 c.notice(_from, 'Invalid argument: %s' % args[0]) 328 return False 329 330 return True 331 246 332 def onmsg_s(self, c, e, to, args): return self.onmsg_status(c, e, to, args) 247 333 def onmsg_status(self, c, e, to, args): … … 385 471 return [product_name, url] 386 472 473 def onact_oper(self, msg, c, e, to): 474 nick = nm_to_n(e.source()) 475 _debug('in oper action: %s to %s in %s' % (msg, nick, to)) 476 c.notice(to, msg) 477 c.mode(to, '+o %s' % nick) 478 return True 479 480 def onact_nooper(self, msg, c, e, to): 481 nick = nm_to_n(e.source()) 482 _debug('in nooper action: %s to %s in %s' % (msg, nick, to)) 483 c.notice(to, msg) 484 c.mode(to, '-o %s' % nick) 485 return True 486 487 def onact_kick(self, msg, c, e, to): 488 nick = nm_to_n(e.source()) 489 _debug('in kick action: %s to %s in %s' % (msg, nick, to)) 490 c.kick(to, nick, msg) 491 return True 492 493 def onact_kick_and_invite(self, msg, c, e, to): 494 nick = nm_to_n(e.source()) 495 _debug('in kick_and_invite action: %s to %s in %s' % (msg, nick, to)) 496 c.kick(to, nick, msg) 497 c.invite(nick, to) 498 return True 499 500 NICK_TRANS_TABLE = string.maketrans('-_i1z2o0s5bdnmft', '_-1i2z0o5sdbmntf') 501 def onact_nick(self, msg, c, e, to): 502 nick = nm_to_n(e.source()) 503 nickto = nick[0] + nick[1:].translate(self.NICK_TRANS_TABLE) 504 if nick == nickto: 505 nickto = nick + '_' 506 _debug('in nick action: %s to %s in %s (%s)' % (msg, nick, to, nickto)) 507 c.notice(to, msg) 508 c.nick(nickto) 509 return True 510 511 def onact_topic(self, msg, c, e, to): 512 nick = nm_to_n(e.source()) 513 _debug('in topic action: %s to %s in %s' % (msg, nick, to)) 514 c.topic(to, msg) 515 return True 516 387 517 if __name__ == '__main__': 388 518 bot = AmazonBot() -
/trunk/amazonbot/my_amazon.py
r8 r24 291 291 u = urllib.FancyURLopener(proxies) 292 292 usock = u.open(url) 293 xmldoc = minidom.parse(usock) 293 xmldoc = None 294 try: 295 xmldoc = minidom.parse(usock) 296 except: 297 raise AmazonError, 'XML Parsing Error' 298 if xmldoc is None: 299 raise AmazonError, 'XML Parsing Error (Result is None)' 294 300 295 301 # from xml.dom.ext import PrettyPrint -
/trunk/amazonbot/amazonbot.ini.sample
r18 r22 1 1 [amazon] 2 locale = jp2 locale = jp 3 3 access_key = your access key 4 4 5 5 [irc] 6 server = irc.freenode.net7 port = 66676 server = irc.freenode.net 7 port = 6667 8 8 channel = #amazonbot 9 9 10 10 [bot] 11 nick = amazonbot 12 content = ãããªã¢ãã¿ã«ããããªã¹ã¹ã¡ 13 thanks = ããããšã 14 sorry = æ£çŽããŸããã£ã 15 bye = ããããªããŸãäŒãæ¥ãŸã§ 16 active_pattern = ããã|ãŽã¡ã³|ããŸã|ã¹ãã³|ãããŸãã 17 silent_pattern = éªé|ãããŸ|ãžã£ã|ãã(ãã|ããŒ)|ã ãŸã 11 nick = amazonbot 12 content = ãããªã¢ãã¿ã«ããããªã¹ã¹ã¡ 13 thanks = ããããšã 14 sorry = æ£çŽããŸããã£ã 15 bye = ããããªããŸãäŒãæ¥ãŸã§ 16 no_products = èŠã€ãããŸããã§ãã 17 active_pattern = ((ããã|ãŽã¡ã³)(ãªãã)?|(ããŸã|ã¹ãã³)|(ã(ã|ã¿)ãŸãã))[ãªãããŒã»âŠ.ããïŒ!]*$ 18 silent_pattern = (éªé|ãããŸ|ãžã£ã|ãã(ãã|ããŒ)|ã ãŸã)[ã ããªãŒ-ïŒ!]*$ 19 20 [action0] 21 input_pattern = ã(æ©|ã¯ã)ãããããŸã 22 message = ãã¯ããããããŸã %s ãã 23 action = oper 24 start_time = 06:00 25 end_time = 12:00 26 27 [action1] 28 input_pattern = ããã²ãšãããã.*ãã¯ãŒãã¡ããªã« 29 message = ããã§ããšãïŒ 18 30 19 31 [freq] -
/trunk/amazonbot/config.py
r8 r28 2 2 3 3 __version__ = '$Revision$' 4 __author__ = 'Atzm WATANABE < sitosito@p.chan.ne.jp>'4 __author__ = 'Atzm WATANABE <atzm@atzm.org>' 5 5 6 6 import os, ConfigParser 7 7 8 8 _userconfig = 'amazonbot.ini' 9 _parser = ConfigParser. SafeConfigParser()9 _parser = ConfigParser.RawConfigParser() 10 10 11 11 def set(sect, key, val): … … 30 30 return '' 31 31 32 def has_section(sect): 33 return _parser.has_section(sect) 34 32 35 def write(filename=''): 33 36 if not filename:
Note: See TracChangeset
for help on using the changeset viewer.