Changeset 9 for trunk/amazonbot
- Timestamp:
- 06/20/06 10:51:20 (18 years ago)
- Location:
- trunk/amazonbot
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/amazonbot/amazonbot.ini.sample
r8 r9 11 11 nick = amazonbot 12 12 content = ãããªã¢ãã¿ã«ããããªã¹ã¹ã¡ 13 thanks = ããããšã 14 sorry = æ£çŽããŸããã£ã 13 15 active_pattern = ããã|ãŽã¡ã³|ããŸã|ã¹ãã³|ãããŸãã 14 16 silent_pattern = éªé|ãããŸ|ãžã£ã|ãã(ãã|ããŒ)|ã ãŸã -
trunk/amazonbot/amazonbot.py
r8 r9 9 9 10 10 import re 11 import sys 11 12 import random 12 13 import MeCab … … 64 65 c.join(config.get('irc', 'channel')) 65 66 if __debug__: 66 print '* Joined %s' % config.get('irc', 'channel')67 print >> sys.stderr, '* Joined %s' % config.get('irc', 'channel') 67 68 68 69 def on_nicknameinuse(self, c, e): … … 73 74 74 75 def on_pubmsg(self, c, e): 75 msg = unicode(e.arguments()[0], 'iso-2022-jp') 76 try: 77 msg = unicode(e.arguments()[0], 'iso-2022-jp') 78 except UnicodeError: 79 if __debug__: 80 print >> sys.stderr, 'ERR: incoming message encoding failed: %s' % e.arguments() 81 return False 76 82 77 self.silence(msg )83 self.silence(msg, c, e) 78 84 if self._silent: 79 85 return False … … 85 91 title, url = self.process_keyword(' '.join(nominals)) 86 92 if title and url: 87 nick = nm_to_n(e.source())88 93 channel = e.target() 89 94 … … 91 96 title = title 92 97 93 message = ('%(content)s: %(title)s <%(url)s>' % locals()).encode('iso-2022-jp') 98 try: 99 message = ('%(content)s: %(title)s %(url)s' % locals()).encode('iso-2022-jp') 100 except UnicodeError: 101 if __debug__: 102 print >> sys.stderr, 'ERR: my message encoding failed: ' 103 print >> sys.stderr, ' * content> %s' % content 104 print >> sys.stderr, ' * title> %s' % title 105 print >> sys.stderr, ' * url> %s' % url 106 return False 107 94 108 c.privmsg(channel, message) 95 109 … … 100 114 ACTIVE_PATTERN = re.compile(config.get('bot', 'active_pattern')) 101 115 SILENT_PATTERN = re.compile(config.get('bot', 'silent_pattern')) 102 def silence(self, msg): 103 if self.ACTIVE_PATTERN.search(msg): 116 def silence(self, msg, c, e): 117 ch = e.target() 118 active = self.ACTIVE_PATTERN.search(msg.encode('utf-8')) 119 silent = self.SILENT_PATTERN.search(msg.encode('utf-8')) 120 if __debug__: 121 print >> sys.stderr, 'ACTIVE_PATTERN: %s, SILENT_PATTERN: %s' % (str(active), str(silent)) 122 123 if active: 104 124 self._silent = False 105 elif self.SILENT_PATTERN.search(msg): 125 c.privmsg(ch, unicode(config.get('bot', 'thanks'), 'utf-8').encode('iso-2022-jp')) 126 elif silent: 106 127 self._silent = True 128 c.privmsg(ch, unicode(config.get('bot', 'sorry'), 'utf-8').encode('iso-2022-jp')) 107 129 108 130 def process_keyword(self, keyword):
Note: See TracChangeset
for help on using the changeset viewer.