Merge lp:~ricardokirkner/lalita/character_command into lp:lalita

Proposed by Ricardo Kirkner
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ricardokirkner/lalita/character_command
Merge into: lp:lalita
Diff against target: 99 lines (+39/-1)
4 files modified
lalita.cfg.sample (+4/-0)
lalita/core/tests/test_events.py (+18/-0)
lalita/core/tests/test_ircbot.py (+9/-0)
lalita/ircbot.py (+8/-1)
To merge this branch: bzr merge lp:~ricardokirkner/lalita/character_command
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+20831@code.launchpad.net

Description of the change

To post a comment you must log in.
137. By Ricardo Kirkner

fixed documentation regarding running code from source directly

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lalita.cfg.sample'
2--- lalita.cfg.sample 2010-02-21 23:17:33 +0000
3+++ lalita.cfg.sample 2010-03-06 20:14:15 +0000
4@@ -4,6 +4,10 @@
5 # License: GPL v3
6 # For further info, see LICENSE file
7
8+# Global Configuration Settings
9+command_char = '@'
10+
11+# Servers Configuration Settings
12 servers = {
13 'localhost': dict (
14 encoding='utf8',
15
16=== modified file 'lalita/core/tests/test_events.py'
17--- lalita/core/tests/test_events.py 2010-01-17 19:03:28 +0000
18+++ lalita/core/tests/test_events.py 2010-03-06 20:14:15 +0000
19@@ -152,6 +152,24 @@
20 self.check_pushed(events.PUBLIC_MESSAGE, "user", "chnl", "blah")
21 return self.deferred
22
23+ def test_privmsg_command_char(self):
24+ '''Calling bot.privmsg with custom command char'''
25+ # set up command char config
26+ _COMMAND_CHAR = ircbot.COMMAND_CHAR
27+
28+ # set custom command char
29+ config = type('config', (object,), {'command_char': '!'})
30+ ircbot.set_global_configuration(config)
31+
32+ # call command and test
33+ bot.privmsg("user", "chnl", "!cmd foo")
34+ self.check_pushed(events.COMMAND, "user", "chnl", "cmd", "foo")
35+
36+ # cleanup
37+ ircbot.COMMAND_CHAR = _COMMAND_CHAR
38+
39+ return self.deferred
40+
41 def test_action(self):
42 '''Calling bot.action'''
43 bot.action("user!foo!bar", "chnl", "blah")
44
45=== modified file 'lalita/core/tests/test_ircbot.py'
46--- lalita/core/tests/test_ircbot.py 2010-02-14 00:24:46 +0000
47+++ lalita/core/tests/test_ircbot.py 2010-03-06 20:14:15 +0000
48@@ -113,3 +113,12 @@
49 self.bot.load_channel_plugins("#testchn3")
50 self.assertEqual(self.results, [])
51
52+ def test_set_global_configuration(self):
53+ _COMMAND_CHAR = ircbot.COMMAND_CHAR
54+
55+ config = type('config', (object,), {'command_char': '!'})
56+ ircbot.set_global_configuration(config)
57+ self.assertEqual(ircbot.COMMAND_CHAR, '!')
58+
59+ ircbot.COMMAND_CHAR = _COMMAND_CHAR
60+
61
62=== modified file 'lalita/ircbot.py'
63--- lalita/ircbot.py 2010-02-20 15:02:51 +0000
64+++ lalita/ircbot.py 2010-03-06 20:14:15 +0000
65@@ -20,6 +20,8 @@
66 # local imports
67 from lalita import dispatcher, events
68
69+COMMAND_CHAR = '@'
70+
71 LOG_LEVELS = {
72 "debug": logging.DEBUG,
73 "info": logging.INFO,
74@@ -151,7 +153,7 @@
75 if msg[0] in (":", " ", ","):
76 msg = msg[1:].strip()
77 self.dispatcher.push(events.TALKED_TO_ME, user, channel, msg)
78- elif msg[0] == '@':
79+ elif msg[0] == COMMAND_CHAR:
80 args = msg.split()
81 command = args.pop(0)[1:]
82 self.dispatcher.push(events.COMMAND, user, channel, command, *args)
83@@ -293,6 +295,10 @@
84 start_manhole(**manhole_opts)
85 reactor.run()
86
87+def set_global_configuration(config):
88+ global COMMAND_CHAR
89+ COMMAND_CHAR = config.command_char
90+
91
92 if __name__ == '__main__':
93 msg = """
94@@ -430,4 +436,5 @@
95 else:
96 manhole_opts = None
97
98+ set_global_configuration(config)
99 main(to_use, plugins_loglvl, manhole_opts=manhole_opts)

Subscribers

People subscribed via source and target branches