- Location:
- /trunk
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/amazonbot/amazonbot.py
r28 r20 3 3 4 4 __version__ = '$Revision$' 5 __author__ = 'Atzm WATANABE < atzm@atzm.org>'5 __author__ = 'Atzm WATANABE <sitosito@p.chan.ne.jp>' 6 6 __date__ = '$Date$' 7 __copyright__ = 'Copyright(C) 2006 -2007Atzm WATANABE, all rights reserved.'7 __copyright__ = 'Copyright(C) 2006 Atzm WATANABE, all rights reserved.' 8 8 __license__ = 'Python' 9 9 10 10 import re 11 import string12 11 import sys 13 12 import time … … 148 147 return method(c, e, to, words[1:]) # words[0] == command name 149 148 150 self.message_action(msg, c, e, to)151 152 149 # silence 153 150 self.silence(msg, c, e, to) … … 220 217 def get_prev_time(self): 221 218 return self._prev_time 222 223 def message_action(self, msg, c, e, to):224 for i in xrange(100):225 action = 'action%d' % i226 if not config.has_section(action):227 break228 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 continue245 except:246 _debug('Invalid time: %s - %s' % (str(c_stime), str(c_etime)))247 continue248 249 pattern = unicoding(config.get(action, 'input_pattern'))250 match = None251 try:252 match = re.search(pattern, msg)253 except:254 _debug('Invalid regexp: %s', pattern)255 continue256 257 if not match:258 continue259 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 continue269 270 if not act:271 c.notice(to, message)272 continue273 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 True281 219 282 220 class AmazonBot(AmazonBotBase): … … 306 244 return 'AmazonBot by %s, based on python-irclib' % __author__ 307 245 308 def onmsg_reload(self, c, e, to, args):309 """Syntax: !reload310 """311 _debug('in reload command: %s', str(args))312 config.read()313 c.notice(to, 'reloaded config')314 return True315 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 False329 330 return True331 332 246 def onmsg_s(self, c, e, to, args): return self.onmsg_status(c, e, to, args) 333 247 def onmsg_status(self, c, e, to, args): … … 471 385 return [product_name, url] 472 386 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 True479 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 True486 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 True492 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 True499 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 True510 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 True516 517 387 if __name__ == '__main__': 518 388 bot = AmazonBot() -
/trunk/amazonbot/my_amazon.py
r24 r8 291 291 u = urllib.FancyURLopener(proxies) 292 292 usock = u.open(url) 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)' 293 xmldoc = minidom.parse(usock) 300 294 301 295 # from xml.dom.ext import PrettyPrint -
/trunk/amazonbot/amazonbot.ini.sample
r22 r18 1 1 [amazon] 2 locale 2 locale = jp 3 3 access_key = your access key 4 4 5 5 [irc] 6 server 7 port 6 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 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 = ããã§ããšãïŒ 11 nick = amazonbot 12 content = ãããªã¢ãã¿ã«ããããªã¹ã¹ã¡ 13 thanks = ããããšã 14 sorry = æ£çŽããŸããã£ã 15 bye = ããããªããŸãäŒãæ¥ãŸã§ 16 active_pattern = ããã|ãŽã¡ã³|ããŸã|ã¹ãã³|ãããŸãã 17 silent_pattern = éªé|ãããŸ|ãžã£ã|ãã(ãã|ããŒ)|ã ãŸã 30 18 31 19 [freq] -
/trunk/amazonbot/config.py
r28 r8 2 2 3 3 __version__ = '$Revision$' 4 __author__ = 'Atzm WATANABE < atzm@atzm.org>'4 __author__ = 'Atzm WATANABE <sitosito@p.chan.ne.jp>' 5 5 6 6 import os, ConfigParser 7 7 8 8 _userconfig = 'amazonbot.ini' 9 _parser = ConfigParser. RawConfigParser()9 _parser = ConfigParser.SafeConfigParser() 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 35 32 def write(filename=''): 36 33 if not filename:
Note: See TracChangeset
for help on using the changeset viewer.