Index: trunk/tools/adminlogbot/adminlog.py |
— | — | @@ -0,0 +1,35 @@ |
| 2 | +site="wikitech.leuksman.com" |
| 3 | +path="/" |
| 4 | +user="More Bots" |
| 5 | +password="..." |
| 6 | +logname="Server admin log" |
| 7 | + |
| 8 | +import mwclient |
| 9 | +import datetime |
| 10 | + |
| 11 | +months=["January","February","March","April","May","June","July","August","September","October","November","December"] |
| 12 | + |
| 13 | +def log(message,author): |
| 14 | + site=mwclient.Site(site, path=path) |
| 15 | + site.login(user,password) |
| 16 | + page=site.Pages[logname] |
| 17 | + text=page.edit() |
| 18 | + lines=text.split('\n') |
| 19 | + position=0 |
| 20 | + # Try extracting latest date header |
| 21 | + for line in lines: |
| 22 | + position+=1 |
| 23 | + if line.startswith("=="): |
| 24 | + undef,month,day,undef=line.split(" ",3) |
| 25 | + break |
| 26 | + |
| 27 | + # Um, check the date |
| 28 | + now=datetime.datetime.utcnow() |
| 29 | + logline="* %02d:%02d %s: %s" % ( now.hour, now.minute, author, message ) |
| 30 | + if months[now.month-1]!=month or now.day!=int(day): |
| 31 | + lines.insert(0,"") |
| 32 | + lines.insert(0,logline) |
| 33 | + lines.insert(0,"== %s %d =="%(months[now.month-1],now.day)) |
| 34 | + else: |
| 35 | + lines.insert(position,logline) |
| 36 | + page.save('\n'.join(lines),"%s (%s)"%(message,author)) |
Index: trunk/tools/adminlogbot/adminlogbot.py |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +import irclib |
| 3 | +import time |
| 4 | +import adminlog |
| 5 | + |
| 6 | +target="#wikimedia-tech" |
| 7 | +nickserv="nickserv" |
| 8 | +nickpassword="..." |
| 9 | + |
| 10 | +def on_connect(con, event): |
| 11 | + con.privmsg(nickserv,"identify "+nickpassword) |
| 12 | + time.sleep(1) |
| 13 | + con.join(target) |
| 14 | + |
| 15 | +def on_msg(con, event): |
| 16 | + if event.target() != target: return |
| 17 | + author,rest=event.source().split('!') |
| 18 | + line=event.arguments()[0] |
| 19 | + if line.startswith("!log "): |
| 20 | + undef,message=line.split(" ",1); |
| 21 | + try: adminlog.log(message,author) |
| 22 | + except: server.privmsg(target,"I failed :(") |
| 23 | + |
| 24 | + |
| 25 | +irc = irclib.IRC() |
| 26 | +server = irc.server() |
| 27 | +server.connect("irc.freenode.net",6667,"morebots") |
| 28 | +server.add_global_handler("welcome", on_connect) |
| 29 | +server.add_global_handler("pubmsg",on_msg) |
| 30 | + |
| 31 | +irc.process_forever() |
Index: trunk/tools/adminlogbot/svn-commit.2.tmp |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +code for bot |
| 3 | +--This line, and those below, will be ignored-- |
| 4 | + |
| 5 | +A . |
Index: trunk/tools/adminlogbot/svn-commit.tmp |
— | — | @@ -0,0 +1,4 @@ |
| 2 | +heee, code for bot |
| 3 | +--This line, and those below, will be ignored-- |
| 4 | + |
| 5 | +A . |
Index: trunk/tools/adminlogbot/README |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +Dependancies: |
| 3 | + mwclient: svn co http:// mwclient.svn.sourceforge.net/viewvc/mwclient/trunk/mwclient/ |
| 4 | + irclib: http://downloads.sourceforge.net/python-irclib/python-irclib-0.4.6.tar.gz?modtime=1135442433&big_mirror=0 |
| 5 | + |
| 6 | +for HTTPS sites one needs to change http.py in mwclient to assign |
| 7 | +HTTPSPersistentCnnection to pool, instead of HTTPPersistentConnection |