jenkins-bot has submitted this change and it was merged.
Change subject: Add a debugging command
......................................................................
Add a debugging command
Add a config flag and command that can be used for debugging the bot.
The first sub-command for debugging will announce all of the events
found on the deploy page to the attached irc channel. This obviously
noisy output should not be directed at any "real" channel but instead
used by attaching to a temporary testing channel just for debugging.
Change-Id: I5a27d38fa7cea976ce421624185a326c3b7f825a
---
M DefaultConfig.yaml
M jouncebot.py
2 files changed, 29 insertions(+), 14 deletions(-)
Approvals:
Alex Monk: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DefaultConfig.yaml b/DefaultConfig.yaml
index 9b2b074..1875f82 100644
--- a/DefaultConfig.yaml
+++ b/DefaultConfig.yaml
@@ -21,3 +21,5 @@
messages:
- '%sDear anthropoid, the time has come. Please deploy %s (%s).'
- '%sRespected human, time to deploy %s (%s). Please do the needful.'
+
+debug: false
diff --git a/jouncebot.py b/jouncebot.py
index 7bc5641..0b27cd9 100755
--- a/jouncebot.py
+++ b/jouncebot.py
@@ -18,25 +18,36 @@
import random
import re
import sys
+import time
class JounceBot(irc.bot.SingleServerIRCBot):
def __init__(self, config, logger, deploy_page):
self.config = config
- irc.bot.SingleServerIRCBot.__init__(
- self,
- [(config['irc']['server'], config['irc']['port'])],
- config['irc']['nick'],
- config['irc']['realname']
- )
self.channel = config['irc']['channel']
self.logger = logger
self.deploy_page = deploy_page
+ self.brain = {
+ 'help': self.do_command_help,
+ 'die': self.do_command_die,
+ 'next': self.do_command_next,
+ 'refresh': self.do_command_refresh,
+ }
+ if self.config['debug']:
+ self.brain['debug'] = self.do_command_debug
+
# Don't even get me started on how stupid a pattern this is
irc.client.ServerConnection.buffer_class = \
irc.buffer.LenientDecodingLineBuffer
+
+ irc.bot.SingleServerIRCBot.__init__(
+ self,
+ [(self.config['irc']['server'], self.config['irc']['port'])],
+ self.config['irc']['nick'],
+ self.config['irc']['realname']
+ )
def on_nicknameinuse(self, conn, event):
self.logger.warning(
@@ -75,7 +86,7 @@
return
def do_command(self, conn, event, source, cmd):
- """ Attempt to perform a given command given to the bot via IRC
+ """Attempt to perform a given command given to the bot via IRC
:param irc.client.ServerConnection conn
:param irc.client.Event event
:param string cmd: String given to the bot via IRC (without bot name)
@@ -87,7 +98,7 @@
cmd = cmd.split(" ", 1)
if cmd[0].lower() in self.brain:
self.brain[cmd[0].lower()](
- self, conn, event, cmd, source, nickmask)
+ conn, event, cmd, source, nickmask)
def do_command_help(self, conn, event, cmd, source, nickmask):
"""Prints the list of all commands known to the server"""
@@ -129,6 +140,14 @@
event.window,
event.url))
+ def do_command_debug(self, conn, event, cmd, source, nickmask):
+ """Debugging commands"""
+ if len(cmd) > 1 and cmd[1] == 'play events':
+ events = self.deploy_page.get_events()
+ for window in sorted(events):
+ self.on_deployment_event(events[window])
+ time.sleep(2)
+
def on_deployment_event(self, next_events):
if len(next_events) > 0:
for event in next_events:
@@ -159,12 +178,6 @@
for line in lines[1:]:
conn.notice(nick, line[indent:])
- brain = {
- 'help': do_command_help,
- 'die': do_command_die,
- 'next': do_command_next,
- 'refresh': do_command_refresh
- }
if __name__ == "__main__":
parser = optparse.OptionParser(usage="usage: %prog [options]")
--
To view, visit https://gerrit.wikimedia.org/r/220677
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5a27d38fa7cea976ce421624185a326c3b7f825a
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/bots/jouncebot
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Dzahn <[email protected]>
Gerrit-Reviewer: Thcipriani <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits