Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: abpbot.py

Issue 29337738: Issue 3703 - Add "coin flip" feature to abpbot (Closed)
Patch Set: Fixed a couple more nits Created Feb. 25, 2016, 8:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | decisionbot.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Simple IRC Bot to announce messages 3 # Simple IRC Bot to announce messages
4 # 4 #
5 # Code originally based on example bot and irc-bot class from 5 # Code originally based on example bot and irc-bot class from
6 # Joel Rosdahl <joel@rosdahl.net>, author of included python-irclib. 6 # Joel Rosdahl <joel@rosdahl.net>, author of included python-irclib.
7 # 7 #
8 8
9 9
10 """ 10 """
11 An IRC bot stub, it will join a particular channel on a server. All 11 An IRC bot stub, it will join a particular channel on a server. All
12 further functionality is implemented by additional handler classes. 12 further functionality is implemented by additional handler classes.
13 """ 13 """
14 14
15 import sys 15 import sys
16 import ConfigParser 16 import ConfigParser
17 from ircbot import SingleServerIRCBot 17 from ircbot import SingleServerIRCBot
18 import irclib 18 import irclib
19 from botcommon import OutputManager 19 from botcommon import OutputManager
20 import logbot, beanbot 20 import logbot, beanbot, decisionbot
21 21
22 # The message returned when someone messages the bot 22 # The message returned when someone messages the bot
23 HELP_MESSAGE = "I am the Adblock Plus logging bot." 23 HELP_MESSAGE = "I am the Adblock Plus logging bot."
24 24
25 def parse_host_port(hostport, default_port=None): 25 def parse_host_port(hostport, default_port=None):
26 lis = hostport.split(":", 1) 26 lis = hostport.split(":", 1)
27 host = lis[0] 27 host = lis[0]
28 if len(lis) == 2: 28 if len(lis) == 2:
29 try: 29 try:
30 port = int(lis[1]) 30 port = int(lis[1])
(...skipping 24 matching lines...) Expand all
55 55
56 SingleServerIRCBot.__init__(self, [ircaddr], self.nickname, self.nickname, 5 ) 56 SingleServerIRCBot.__init__(self, [ircaddr], self.nickname, self.nickname, 5 )
57 self.queue = OutputManager(self.connection, .9) 57 self.queue = OutputManager(self.connection, .9)
58 self.queue.start() 58 self.queue.start()
59 59
60 self.handlers = {} 60 self.handlers = {}
61 61
62 def handler_for_key(self, key): 62 def handler_for_key(self, key):
63 return lambda c, e: self.execute_handlers(key, c, e) 63 return lambda c, e: self.execute_handlers(key, c, e)
64 64
65 for handler in logbot.Logbot(config, self.queue), beanbot.Beanbot(config, se lf.queue): 65 for handler in (logbot.Logbot(config, self.queue),
66 beanbot.Beanbot(config, self.queue),
67 decisionbot.Decisionbot(config, self.queue)):
66 for props in handler.__dict__, handler.__class__.__dict__: 68 for props in handler.__dict__, handler.__class__.__dict__:
67 for key in props.iterkeys(): 69 for key in props.iterkeys():
68 if not key.startswith('on_'): 70 if not key.startswith('on_'):
69 continue 71 continue
70 value = getattr(handler, key) 72 value = getattr(handler, key)
71 if not hasattr(value, '__call__'): 73 if not hasattr(value, '__call__'):
72 continue 74 continue
73 75
74 if not key in self.handlers: 76 if not key in self.handlers:
75 # Set up handling for this message 77 # Set up handling for this message
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 usage() 132 usage()
131 133
132 configfile = sys.argv[1] 134 configfile = sys.argv[1]
133 135
134 config = ConfigParser.ConfigParser() 136 config = ConfigParser.ConfigParser()
135 config.read(configfile) 137 config.read(configfile)
136 Bot(config) 138 Bot(config)
137 139
138 if __name__ == "__main__": 140 if __name__ == "__main__":
139 main() 141 main()
OLDNEW
« no previous file with comments | « no previous file | decisionbot.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld