Skip to content

Commit

Permalink
Merge branch 'master' of git+ssh://git.otfbot.org:2066/otfbot/otfbot
Browse files Browse the repository at this point in the history
  • Loading branch information
cato- committed Apr 12, 2012
2 parents a97dac3 + 33d892c commit d69d1bc
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 55 deletions.
12 changes: 7 additions & 5 deletions helpers/munin-plugins/irclpm
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ config=False
if len(sys.argv) >= 2 and sys.argv[1]=="config":
config=True
print "graph_title IRC Lines per Minute"
print "graph_vlabel \"# Lines\""
print "graph_vlabel num. lines"
print "graph_category chat"
print "graph_scale no"

for line in data.split("\n"):
line2=re.sub("[\#\:-]", "", line)
line2=re.sub("[\#-]", "", line)
line3=re.sub("[\:\#]", "", line)
if not line2:
continue
if not config:
print line2.replace(".", "", 1)
print line2.replace(".", "_", 1).replace(":", ".value", 1)
else:
print re.sub("\.", "", line2.split(" ")[0])+".label", line2.split(" ")[0]
print re.sub("\.", "", line2.split(" ")[0])+".min", 0
print re.sub("\.", "_", line3.split(" ")[0]).replace("-", "")+".label", line3.split(" ")[0]
print re.sub("\.", "_", line3.split(" ")[0]).replace("-", "")+".min", 0
27 changes: 22 additions & 5 deletions helpers/munin-plugins/ircuser
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,37 @@ url=urllib2.urlopen("http://localhost:8080/users")
data=url.read()
url.close()

url=urllib2.urlopen("http://localhost:8080/active_users")
data2=url.read()
url.close()

config=False
if len(sys.argv) >= 2 and sys.argv[1]=="config":
config=True
print "graph_title IRC Users"
print "graph_vlabel \"# User\""
print "graph_vlabel num. users"
print "graph_category chat"
print "graph_scale no"

#TODO: refactor me
for line in data.split("\n"):
line2=re.sub("[\#\:-]", "", line)
line2=re.sub("[\#-]", "", line)
line3=re.sub("[\:\#]", "", line)
if not line2:
continue
if not config:
print line2.replace(".", "_", 1).replace(":", ".value", 1)
else:
print re.sub("\.", "_", line3.split(" ")[0]).replace("-", "")+".label", line3.split(" ")[0]
print re.sub("\.", "_", line3.split(" ")[0]).replace("-", "")+".min", 0

for line in data2.split("\n"):
line2=re.sub("[\#-]", "", line)
line3=re.sub("[\:\#]", "", line)
if not line2:
continue
if not config:
print line2.replace(".", "", 1)
print line2.replace(".", "_", 1).replace(":", "_active.value", 1)
else:
print re.sub("\.", "", line2.split(" ")[0])+".label", line2.split(" ")[0]
print re.sub("\.", "", line2.split(" ")[0])+".min", 0
print re.sub("\.", "_", line3.split(" ")[0]).replace("-", "")+"_active.label", line3.split(" ")[0]
print re.sub("\.", "_", line3.split(" ")[0]).replace("-", "")+"_active.min", 0
49 changes: 49 additions & 0 deletions otfbot/plugins/ircClient/checkbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file is part of OtfBot.
#
# OtfBot is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# OtfBot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OtfBot; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# (c) 2012 by Alexander Schier
#

"""
mark a checkbox from a list of checkboxes
"""
from otfbot.lib import chatMod
from otfbot.lib.pluginSupport.decorators import callback

import random, re


class Plugin(chatMod.chatMod):
""" checkbox plugin """

def __init__(self, bot):
self.bot = bot

@callback
def msg(self, user, channel, msg):
if self.bot.nickname.lower() != user.getNick().lower() and "[ ]" in msg:
parts = re.split("\[ \]", msg)
check = random.randint(1, len(parts) -1)
count=1
msg=parts[0]
for part in parts[1:]:
if check == count:
msg += "[x]"
else:
msg += "[ ]"
msg += parts[count]
count += 1
self.bot.sendmsg(channel, msg)
23 changes: 15 additions & 8 deletions otfbot/plugins/ircClient/quotesfromweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ def command(self, user, channel, command, options):
desc = desc.replace(re.findall('<p.*class=".+">.+</p>',desc)[0],"")
self.bot.msg(channel,"\"" + desc + "\" (" + zitat['title'].encode("utf8") + ")")
return
elif command == "sprichwort":
url=urllib2.urlopen("http://www.sprichwortrekombinator.de")
elif command == "proverb":
url=urllib2.urlopen("http://proverb.gener.at/or/")
elif command == "sprichwort" or command == "proverb":
if command == "sprichwort":
url=urllib2.urlopen("http://www.sprichwortrekombinator.de")
elif command == "proverb":
url=urllib2.urlopen("http://proverb.gener.at/or/")
data=url.read()
url.close()
sprichwort=re.search("<div class=\"spwort\">([^<]*)<\/div>", data, re.S).group(1)
self.bot.sendmsg(channel, sprichwort)
elif command == "commitmsg":
url=urllib2.urlopen("http://whatthecommit.com/")
data=url.read()
url.close()
msg = re.search("<p>(.*)", data).group(1)
self.bot.sendmsg(channel, msg)
else:
return
data=url.read()
url.close()
sprichwort=re.search("<div class=\"spwort\">([^<]*)<\/div>", data, re.S).group(1)
self.bot.sendmsg(channel, sprichwort)
48 changes: 26 additions & 22 deletions otfbot/plugins/ircClient/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,37 @@ def __init__(self, bot):
self.bot=bot
self.peak={}
self.peak_date={}
self.linesperminute = {}
self.new_lines = {}
self.timestamp = {}
self.timestamps = {}
self.AVERAGE_MINUTES = 5.0

@callback
def msg(self, user, channel, msg):
self.calcLPM(channel)
self.new_lines[channel][-1] += 1
self.addTs(channel, user)

def calcLPM(self, channel):
def removeOldTimestamps(self, channel):
new_timestamp = int(time.time())
if not channel in self.timestamp:
self.timestamp[channel] = new_timestamp
if not channel in self.new_lines:
self.new_lines[channel] = [0, 0, 0, 0, 0]
no_lines = reduce(lambda x, y: x + y, self.new_lines[channel][:-1])
timediff = new_timestamp - self.timestamp[channel]
if timediff >0:
self.linesperminute[channel] = no_lines * 60 / 4.0 / timediff
if timediff >=60:
self.new_lines[channel] = self.new_lines[channel][1:]
self.new_lines[channel].append(0)
self.timestamp[channel] = new_timestamp
while len(self.timestamps[channel]) and new_timestamp - self.timestamps[channel][0][0] > self.AVERAGE_MINUTES*60:
self.timestamps[channel].pop(0)

def addTs(self, channel, user):
new_timestamp = int(time.time())
if not channel in self.timestamps:
self.timestamps[channel] = [(new_timestamp, user)]
else:
self.timestamps[channel].append((new_timestamp, user))
self.removeOldTimestamps(channel)

def getLinesPerMinute(self, channel):
self.calcLPM(channel)
if not channel in self.linesperminute:
self.linesperminute[channel] = 0
return self.linesperminute[channel]
if not channel in self.timestamps:
return 0
self.removeOldTimestamps(channel)
return len(self.timestamps[channel]) / self.AVERAGE_MINUTES

def getActiveUsersCount(self, channel):
if not channel in self.timestamps:
return 0
self.removeOldTimestamps(channel)
return len(set(map(lambda x:x[1], self.timestamps[channel])))

@callback
def joined(self, channel):
Expand All @@ -85,3 +87,5 @@ def command(self, user, channel, command, options):
self.bot.sendmsg(channel, "Maximale Nutzerzahl (%s) erreicht am %s"%(self.peak[channel], self.peak_date[channel]))
elif command == "lpm":
self.bot.sendmsg(channel, "aktuelle Zeilen pro Minute: %s"%(self.getLinesPerMinute(channel)))
elif command == "activeusers":
self.bot.sendmsg(channel, "Aktive Nutzer: %s"%(self.getActiveUsersCount(channel)))
39 changes: 24 additions & 15 deletions otfbot/plugins/webServer/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,36 @@ def GET(self, path, headers, rfile, wfile, handler):
if not ns[n] or not ns[n].protocol:
self.logger.warning("Error, %s is not connected."%n)
continue
cud=ns[n].protocol.getChannelUserDict()
for c in cud:
#cud=ns[n].protocol.getChannelUserDict()
for c in ns[n].protocol.channels:
ops=0
hops=0
voices=0
for user in cud[c].keys():
if cud[c][user] & ns[n].protocol.rev_modchars['o']:
ops+=1
elif cud[c][user] & ns[n].protocol.rev_modchars['h']:
hops+=1
elif cud[c][user] & ns[n].protocol.rev_modchars['v']:
voices+=1
wfile.write("%s.%s: %s\n"%(n, c, len(cud[c])))
#wfile.write("%s.%s.total: %s\n"%(n, c, len(cud[c])))
#wfile.write("%s.%s.ops: %s\n"%(n, c, ops))
#wfile.write("%s.%s.hops: %s\n"%(n, c, hops))
#wfile.write("%s.%s.voices: %s\n"%(n, c, voices))
#for user in cud[c].keys():
# if cud[c][user] & ns[n].protocol.rev_modchars['o']:
# ops+=1
# elif cud[c][user] & ns[n].protocol.rev_modchars['h']:
# hops+=1
# elif cud[c][user] & ns[n].protocol.rev_modchars['v']:
# voices+=1
#wfile.write("%s.%s: %s\n"%(n, c, len(cud[c])))
output = "%s.%s: %s\n"%(n, c, len(ns[n].protocol.getUsers(c)))
wfile.write(output)
##wfile.write("%s.%s.total: %s\n"%(n, c, len(cud[c])))
##wfile.write("%s.%s.ops: %s\n"%(n, c, ops))
##wfile.write("%s.%s.hops: %s\n"%(n, c, hops))
##wfile.write("%s.%s.voices: %s\n"%(n, c, voices))
if path=='/lines':
for network in self.wps.root.getServiceNamed("ircClient").services:
if network and network.protocol: #no NoneType Exception on disconnected network
for channel in network.protocol.getChannelUserDict().keys():
for channel in network.protocol.channels:
if not wfile.closed:
wfile.write("%s.%s: %s\n"%(network.name, channel, network.protocol.plugins['ircClient.statistics'].getLinesPerMinute(channel)))
if path=='/active_users':
#TODO: duplicate code, refactor me!
for network in self.wps.root.getServiceNamed("ircClient").services:
if network and network.protocol: #no NoneType Exception on disconnected network
for channel in network.protocol.channels:
if not wfile.closed:
wfile.write("%s.%s: %s\n"%(network.name, channel, network.protocol.plugins['ircClient.statistics'].getActiveUsersCount(channel)))
#app.getServiceNamed("ircClient").services[0].protocol.plugins['plugins.ircClient.ki']

0 comments on commit d69d1bc

Please sign in to comment.