-
Notifications
You must be signed in to change notification settings - Fork 5
/
wikilogbot.py
102 lines (95 loc) · 4.09 KB
/
wikilogbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Script to log messages to a wikipage from IRC
# For help on installing, check README
# version 1.0.2
#
# (C) Krinkle, 2010-2012
# (C) Pywikipedia bot team, 2003-2010
#
# Distributed under the terms of the MIT license.
#
from ircbot import SingleServerIRCBot
from irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr
import time
import datetime
import wikilog
class LogBot(SingleServerIRCBot):
def __init__(self, joinchannels, nickname, server, port, nickserv, nickservpassword, initialstatus, msgs_help, info_help):
SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.joinchannels = joinchannels
self.nickname = nickname
self.nickserv = nickserv
self.nickservpassword = nickservpassword
self.currentstatus = initialstatus
self.msgs_help = msgs_help
self.info_help = info_help
self.statuslastmodtime = u'?'
self.statuslastmodauthor = u'?'
self.monthsnames=["January","February","March","April","May","June","July","August","September","October","November","December"]
def on_nicknameinuse(self, c, e):
c.nick(c.get_nickname() + "_")
def on_unavailresource(self, c, e):
c.nick(c.get_nickname() + "_")
def on_welcome(self, c, e):
c.privmsg(self.nickserv,"identify "+self.nickservpassword)
c.privmsg(self.nickserv,"ghost "+self.nickname+" "+self.nickservpassword)
c.privmsg(self.nickserv,"release "+self.nickname+" "+self.nickservpassword)
time.sleep(1)
for ch in self.joinchannels:
c.join(ch)
def on_pubmsg(self, c, e):
author,rest=e.source().split('!')
line=e.arguments()[0]
chan=self.channels[e.target()]
if chan.is_voiced(author) or chan.is_oper(author):
if line.startswith("!help"):
c.privmsg(e.target(),self.msgs_help)
if line.startswith("!info"):
c.privmsg(e.target(),self.info_help)
if line.startswith("!log "):
undef,message=line.split(" ",1);
try:
wikilog.log(message,author)
c.privmsg(e.target(),"Logged the message ( http://bit.ly/clogger ), "+author+".")
except: c.privmsg(e.target(),"I failed :(")
elif line.startswith("!rights "):
undef,message=line.split(" ",1);
try:
wikilog.rights(message,author)
c.privmsg(e.target(),"Rights log ( http://bit.ly/rightslog ) has been updated, "+author+".")
except: c.privmsg(e.target(),"I failed :(")
elif line.startswith("!disconnect"):
self.disconnect()
elif line.startswith("!exit"):
self.die()
elif line.startswith("!donick "):
undef,message=line.split(" ",1);
c.nick(message)
elif line.startswith("!updatestatus "):
undef,message=line.split(" ",1);
try:
self.currentstatus = message
now=datetime.datetime.utcnow()
self.statuslastmodtime = "%02d:%02d, %d %s %d" % ( now.hour, now.minute, now.day, self.monthsnames[now.month-1], now.year )
self.statuslastmodauthor = author
c.privmsg(e.target(),"Status updated, "+author+".")
except:
c.privmsg(e.target(), "Error updating status, "+author+".")
elif line.startswith("!status"):
c.privmsg(e.target(),"Status: "+self.currentstatus+" (Last modified by "+self.statuslastmodauthor+" at "+self.statuslastmodtime+")")
else:
if line.startswith("!status"):
c.privmsg(e.target(),"Status: "+self.currentstatus+" (Last modified by "+self.statuslastmodauthor+" at "+self.statuslastmodtime+")")
def main():
server=u"irc.freenode.net"
port=6667
joinchannels=["#botwar"]
nickname=u"wikilogbot"
nickserv=u"NickServ"
initialstatus=u"All OK!"
msgs_help=u"Give right: {{Right given|NickServname|Wikiname|rightstemplate|channel|diffid=000}} | Remove right: {{Right removed|NickServname|Wikiname|rightstemplate|channel|comment=Reason here}} (see !info for useful links)"
info_help=u"Mailing list (*new*): http://bit.ly/cvnLatest / http://bit.ly/cvnMonth | Subscribe: https://lists.wikimedia.org/mailman/listinfo/cvn | Server admin Log: http://bit.ly/clogger | Rights log: http://bit.ly/rightslog | Toolserver: http://toolserver.org/~cvn/"
nickservpassword=u"*******"
bot = LogBot(joinchannels, nickname, server, port, nickserv, nickservpassword, initialstatus, msgs_help, info_help)
bot.start()
if __name__ == "__main__":
main()