Changeset 22 for trunk/amazonbot
- Timestamp:
- 02/09/07 14:19:24 (18 years ago)
- Location:
- trunk/amazonbot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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/amazonbot.py
r20 r22 5 5 __author__ = 'Atzm WATANABE <sitosito@p.chan.ne.jp>' 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 … … 147 147 return method(c, e, to, words[1:]) # words[0] == command name 148 148 149 self.message_action(msg, c, e, to) 150 149 151 # silence 150 152 self.silence(msg, c, e, to) … … 217 219 def get_prev_time(self): 218 220 return self._prev_time 221 222 def message_action(self, msg, c, e, to): 223 for i in xrange(100): 224 action = 'action%d' % i 225 if not config.has_section(action): 226 break 227 228 c_stime = config.get(action, 'start_time') 229 c_etime = config.get(action, 'end_time') 230 231 try: 232 if c_stime and c_etime: 233 now = time.time() 234 [now_y, now_m, now_d] = time.localtime(now)[:3] 235 236 stime = '%04d/%02d/%02d %s' % (now_y, now_m, now_d, c_stime) 237 etime = '%04d/%02d/%02d %s' % (now_y, now_m, now_d, c_etime) 238 stime = time.mktime(time.strptime(stime, '%Y/%m/%d %H:%M')) 239 etime = time.mktime(time.strptime(etime, '%Y/%m/%d %H:%M')) 240 241 if not ((stime <= now) and (now <= etime)): 242 _debug('Out of time: %s - %s' % (c_stime, c_etime)) 243 continue 244 except: 245 _debug('Invalid time: %s - %s' % (str(c_stime), str(c_etime))) 246 continue 247 248 match = re.search(unicoding(config.get(action, 'input_pattern')), msg) 249 if not match: 250 continue 251 252 act = config.get(action, 'action') 253 fmt = config.get(action, 'message') 254 try: 255 _from = nm_to_n(e.source()) 256 message = ununicoding(fmt % _from) 257 258 if not message: 259 _debug('No message specified') 260 continue 261 262 if not act: 263 c.notice(to, message) 264 continue 265 266 method = getattr(self, 'onact_%s' % act, lambda *arg: False) 267 method(message, c, e, to) 268 269 except KeyboardInterrupt: 270 _debug('Action failed: %s (%s)' % (str(act), str(fmt))) 271 272 return True 219 273 220 274 class AmazonBot(AmazonBotBase): … … 244 298 return 'AmazonBot by %s, based on python-irclib' % __author__ 245 299 300 def onmsg_lt(self, c, e, to, args): return self.onmsg_localtime(c, e, to, args) 301 def onmsg_localtime(self, c, e, to, args): 302 """Syntax: !localtime <unix time> 303 """ 304 _debug('in localtime command: %s', str(args)) 305 306 _from = nm_to_n(e.source()) 307 try: 308 sec = float(args[0]) 309 c.notice(_from, time.strftime('%b %d %T', time.localtime(sec))) 310 except ValueError, e: 311 c.notice(_from, 'Invalid argument: %s' % args[0]) 312 return False 313 314 return True 315 246 316 def onmsg_s(self, c, e, to, args): return self.onmsg_status(c, e, to, args) 247 317 def onmsg_status(self, c, e, to, args): … … 385 455 return [product_name, url] 386 456 457 def onact_oper(self, msg, c, e, to): 458 nick = nm_to_n(e.source()) 459 _debug('in oper action: %s to %s in %s' % (msg, nick, to)) 460 c.notice(to, msg) 461 c.mode(to, '+o %s' % nick) 462 return True 463 464 def onact_nooper(self, msg, c, e, to): 465 nick = nm_to_n(e.source()) 466 _debug('in nooper action: %s to %s in %s' % (msg, nick, to)) 467 c.notice(to, msg) 468 c.mode(to, '-o %s' % nick) 469 return True 470 471 def onact_kick(self, msg, c, e, to): 472 nick = nm_to_n(e.source()) 473 _debug('in kick action: %s to %s in %s' % (msg, nick, to)) 474 c.kick(to, nick, msg) 475 return True 476 477 def onact_kick_and_invite(self, msg, c, e, to): 478 nick = nm_to_n(e.source()) 479 _debug('in kick_and_invite action: %s to %s in %s' % (msg, nick, to)) 480 c.kick(to, nick, msg) 481 c.invite(nick, to) 482 return True 483 484 def onact_nick(self, msg, c, e, to): 485 nick = nm_to_n(e.source()) 486 _debug('in nick action: %s to %s in %s' % (msg, nick, to)) 487 c.notice(to, msg) 488 c.nick('%s_' % nick) 489 return True 490 491 def onact_topic(self, msg, c, e, to): 492 nick = nm_to_n(e.source()) 493 _debug('in topic action: %s to %s in %s' % (msg, nick, to)) 494 c.topic(to, msg) 495 return True 496 387 497 if __name__ == '__main__': 388 498 bot = AmazonBot() -
trunk/amazonbot/config.py
r8 r22 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.