Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: melmothx/jsonbot
base: 556f411d2e
...
head fork: melmothx/jsonbot
compare: 5c0cfea06d
  • 12 commits
  • 17 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 26, 2011
Marco Fixed the geo string
	modified:   jsb/plugs/common/geo.py
18f5f34
Marco Enhancement for karma.py
	modified:   jsb/plugs/common/karma.py

Catch all the ++|--, but only if at the beginning of the line.

Also, avoid self-incrementing (cheating)
26dc2a3
Bart Thate branch merge 40d5695
Commits on Mar 27, 2011
Bart Thate dont check for "] [" to prevent looping .. use the event.isrelay flag ff10b82
Bart Thate fix colors stuff 8890d63
Bart Thate fix relay looping 2c9062c
Commits on Mar 28, 2011
Bart Thate lower loglevels a972566
Bart Thate branch merge ce9960e
Bart Thate branch merge ... thnx melmothx 88808cb
Commits on Mar 29, 2011
Bart Thate lower loglevels .. move geo and dns plugins to jsb/plugs/socket
--HG--
rename : jsb/plugs/common/dns.py => jsb/plugs/socket/dns.py
rename : jsb/plugs/common/geo.py => jsb/plugs/socket/geo.py
4dadd76
Bart Thate fix geo command b3bc7d7
Bart Thate check for . in hostname 5c0cfea
View
5 jsb/lib/botbase.py
@@ -360,7 +360,7 @@ def makeoutput(self, printto, txt, result=[], nr=375, extend=0, dot=", ", origin
if not txt: return ""
txt = self.makeresponse(txt, result, dot)
res1, nritems = self.less(origin or printto, txt, nr+extend)
- return self.outputmorphs.do(res1)
+ return res1
def out(self, printto, txt, how="msg", event=None, origin=None, html=False, *args, **kwargs):
self.outnocb(printto, txt, how, event=event, origin=origin, html=html, *args, **kwargs)
@@ -387,11 +387,13 @@ def say(self, channel, txt, result=[], how="msg", event=None, nr=375, extend=0,
if event and event.showall: txt = self.makeresponse(txt, result, dot, *args, **kwargs)
else: txt = self.makeoutput(channel, txt, result, nr, extend, dot, origin=target, *args, **kwargs)
if txt:
+ txt = self.outputmorphs.do(txt, event)
self.out(target, txt, how, event=event, origin=target, *args, **kwargs)
if event: event.resqueue.put_nowait(txt) ; event.outqueue.put_nowait(txt)
def saynocb(self, channel, txt, result=[], how="msg", event=None, nr=375, extend=0, dot=", ", *args, **kwargs):
txt = self.makeoutput(channel, txt, result, nr, extend, dot, *args, **kwargs)
+ txt = self.outputmorphs.do(txt, event)
if txt: self.outnocb(channel, txt, how, event=event, origin=channel, *args, **kwargs)
def less(self, printto, what, nr=365):
@@ -529,6 +531,7 @@ def normalize(self, what):
""" convert markup to IRC bold. """
txt = strippedtxt(what, ["\002", "\003"])
txt = re.sub("\s+", " ", what)
+ txt = stripcolor(txt)
txt = txt.replace("\003", '')
txt = txt.replace("\002", "*")
txt = txt.replace("<b>", "*")
View
11 jsb/lib/commands.py
@@ -127,15 +127,9 @@ def dispatch(self, bot, event, wait=0):
event.bind(bot)
if event.groupchat: id = event.auth = event.userhost
else: id = event.auth
- #if bot.cfg.auto_register: bot.users.addguest(id)
if not event.user: raise NoSuchUser(event.auth)
- #if not event.user:
- # event.user = bot.users.getuser(id)
- # if event.user: event.userstate = UserState(event.user.data.name)
- # else: logging.debug("failed to set user %s" % id)
c = self.woulddispatch(bot, event)
if not c: raise NoSuchCommand()
- ## core business
if bot.cmndperms and bot.cmndperms[c.cmnd]: perms = bot.cmndperms[c.cmnd]
else: perms = c.perms
if bot.allowall: return self.doit(bot, event, c, wait=wait)
@@ -164,10 +158,7 @@ def doit(self, bot, event, target, wait=0):
event.txt = event.origtxt
start_botevent(bot, event, event.speed)
event.reply("task started for %s" % event.auth)
- else:
- target.func(bot, event)
- event.ready()
- return event
+ else: target.func(bot, event) ; event.ready() ; return event
else:
if target.threaded and not event.nothreads:
logging.warning("commands - launching thread for %s" % event.usercmnd)
View
5 jsb/lib/eventbase.py
@@ -43,6 +43,7 @@ def __init__(self, input={}, bot=None):
LazyDict.__init__(self)
if bot: self.bot = bot
self.bottype = "botbase"
+ self.relayed = []
self.copyin(input)
def __deepcopy__(self, a):
@@ -84,12 +85,12 @@ def bind(self, bot=None, user=None, chan=None):
if cfg.auto_register:
bot.users.addguest(target)
self.user = user or bot.users.getuser(target)
- logging.warn("eventbase - binding user - %s - from %s" % (str(self.user), whichmodule()))
+ logging.info("eventbase - binding user - %s - from %s" % (str(self.user), whichmodule()))
if not self.chan:
if chan: self.chan = chan
elif self.channel: self.chan = ChannelBase(self.channel, bot.botname)
elif self.userhost: self.chan = ChannelBase(self.userhost, bot.botname)
- logging.warn("eventbase - binding channel - %s" % str(self.chan))
+ logging.info("eventbase - binding channel - %s" % str(self.chan))
if not self.user: logging.info("eventbase - no %s user found .. setting nodispatch" % target) ; self.nodispatch = True
self.prepare(bot)
return self
View
6 jsb/lib/runner.py
@@ -79,7 +79,7 @@ def handle(self, descr, func, bot, ievent, *args, **kwargs):
self.finished = time.time()
self.elapsed = self.finished - self.starttime
if self.elapsed > 3:
- logging.warn('runner - ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
+ logging.info('runner - ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
if ievent.iscommand: ievent.ready()
#ievent.ready()
except Exception, ex:
@@ -115,7 +115,7 @@ def start(self):
def put(self, *data):
""" put a job on a free runner. """
- logging.warn("runners - size is %s" % len(self.runners))
+ logging.debug("runners - size is %s" % len(self.runners))
for runner in self.runners:
if not runner.queue.qsize():
runner.put(*data)
@@ -144,7 +144,7 @@ def makenew(self):
def cleanup(self):
""" clean up idle runners. """
- if not len(self.runners): logging.info("nothing to clean")
+ if not len(self.runners): logging.debug("nothing to clean")
for index in range(len(self.runners)-1, -1, -1):
runner = self.runners[index]
logging.debug("runner - cleanup %s" % runner.name)
View
4 jsb/lib/socklib/irc/irc.py
@@ -90,7 +90,7 @@ def _raw(self, txt):
try:
self.lastoutput = time.time()
itxt = toenc(txt, self.encoding)
- logging.warn(u"%s - out - %s" % (self.name, itxt))
+ logging.info(u"%s - out - %s" % (self.name, itxt))
if not self.sock: logging.warn("%s - socket disappeared - not sending." % self.name) ; return
if self.cfg.has_key('ssl') and self.cfg['ssl']: self.sock.write(itxt + '\n')
else: self.sock.send(itxt[:500] + '\n')
@@ -195,7 +195,7 @@ def _readloop(self):
intxt = intxt[:-1]
for r in intxt:
try:
- r = strippedtxt(r.rstrip(), ["\001", "\002"])
+ r = strippedtxt(r.rstrip(), ["\001", "\002", "\003"])
rr = unicode(fromenc(r.rstrip(), self.encoding))
except UnicodeDecodeError:
logging.warn("%s - decode error - ignoring" % self.name)
View
2  jsb/lib/socklib/irc/ircevent.py
@@ -80,6 +80,8 @@ def parse(self, bot, rawstr):
self.ruserhost = self.userhost
self.stripped = self.userhost
self.auth = self.userhost
+ try: self.hostname = self.userhost.split("@")[1]
+ except: self.hostname = None
self.origtxt = self.txt
if self.channel:
self.channel = self.channel.strip()
View
3  jsb/plugs/common/colors.py
@@ -25,8 +25,9 @@
## the morph
-def docolormorph(txt):
+def docolormorph(txt, event):
if not txt: return txt
+ if event and not event.bottype == "irc": return txt
splitted = txt.split()
for s in splitted:
for t, color in state.data.colormapping.iteritems():
View
3  jsb/plugs/common/forward.py
@@ -17,7 +17,7 @@
from jsb.lib.errors import NoProperDigest
from jsb.utils.exception import handle_exception
from jsb.utils.locking import locked
-from jsb.utils.generic import strippedtxt
+from jsb.utils.generic import strippedtxt, stripcolor
## jsb.plugs.common imports
@@ -86,6 +86,7 @@ def forwardoutcb(bot, event):
if outbot:
e.source = outbot.jid
txt = outbot.normalize(e.tojson())
+ txt = stripcolor(txt)
#txt = e.tojson()
container = Container(outbot.jid, txt)
outbot.outnocb(jid, container.tojson())
View
51 jsb/plugs/common/geo.py
@@ -1,51 +0,0 @@
-# jsb/plugs/common/geo.py
-#
-#
-
-""" This product includes GeoLite data created by MaxMind, available from http://maxmind.com/ """
-
-
-## jsb imports
-
-from jsb.lib.commands import cmnds
-from jsb.utils.url import geturl2
-from jsb.imports import getjson
-
-## system imports
-from socket import gethostbyname
-import re
-## defines
-
-URL = "http://geoip.pidgets.com/?ip=%s&format=json"
-
-def querygeoipserver(ip):
- ipinfo = getjson().loads(geturl2(URL % ip))
- return ipinfo
-
-## geo command
-
-def handle_geo(bot, event):
- if not event.rest:
- event.missing("<ip>")
- return
- query = event.rest.strip()
- ippattern = re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", query)
- hostpattern = re.match(r"(\w+://)?(?P<hostname>\S+\.\w+)", query)
- ip = ""
- if ippattern:
- ip = ippattern.group(0)
-
- elif hostpattern:
- try:
- ip = gethostbyname(hostpattern.group('hostname'))
- except:
- event.reply("Couldn't look up the hostname")
- return
-
- else: return
-
- event.reply("geo of %s is: " % ip, querygeoipserver(ip))
-
-
-
-cmnds.add("geo", handle_geo, ["OPER", "GEO"])
View
14 jsb/plugs/common/relay.py
@@ -11,8 +11,9 @@
from jsb.lib.persist import PlugPersist
from jsb.lib.examples import examples
from jsb.lib.fleet import getfleet
-from jsb.utils.exception import handle_exception
from jsb.lib.errors import NoSuchWave
+from jsb.utils.exception import handle_exception
+from jsb.utils.generic import stripcolor
## basic imports
@@ -36,7 +37,11 @@
def relayprecondition(bot, event):
""" check to see whether the callback needs to be executed. """
- if event.forwarded: return False
+ if event.forwarded: return
+ splitted = event.txt.split("]")
+ try: bn = splitted[0][1:]
+ except: bn = None
+ if event.nick == bot.nick and not event.iscommand: logging.info("relay - %s already relayed" % bot.nick) ; return
origin = event.printto or event.channel
logging.debug("relay - precondition - origin is %s" % origin)
if event.txt:
@@ -61,6 +66,7 @@ def relaycallback(bot, event):
logging.debug('trying relay of %s to (%s,%s)' % (origin, type, target))
# tests to prevent looping
if botname == bot.botname and origin == target: continue
+ if bot.name in event.relayed: continue
# check whether relay is blocked
if block.data.has_key(origin):
if [botname, type, target] in block.data[origin]: continue
@@ -75,8 +81,8 @@ def relaycallback(bot, event):
txt = event.txt
else:
txt = "[%s] %s" % (event.nick, event.txt)
- if txt.find('] [') != -1: continue
- outbot.saynocb(target, txt)
+ txt = stripcolor(txt)
+ outbot.outnocb(target, txt, event=event)
else: logging.error("can't find %s bot" % type)
except Exception, ex: handle_exception()
except KeyError: pass
View
5 jsb/plugs/core/dispatch.py
@@ -34,7 +34,7 @@ def predispatch(bot, event):
def dispatch(bot, event):
""" dispatch an event. """
- logging.warn("dispatch - doing event %s" % event.dump())
+ logging.info("dispatch - doing event %s" % event.dump())
if event.userhost in bot.ignore: logging.warn("%s - ignore on %s" % (bot.name, event.userhost)) ; return
if event.nodispatch:
logging.debug("dispatch - nodispatch option is set - ignoring %s" % event.userhost)
@@ -44,7 +44,7 @@ def dispatch(bot, event):
bot.curevent = event
go = False
execstr = event.iscmnd()
- logging.warn("dispatch - execstr is %s" % execstr)
+ logging.debug("dispatch - execstr is %s" % execstr)
try:
if execstr:
event.iscommand = True
@@ -57,7 +57,6 @@ def dispatch(bot, event):
e.bind(bot)
if e.usercmnd in event.chan.data.silentcommands: e.silent = True
result = bot.plugs.dispatch(bot, e)
- #event.leave()
else:
logging.debug("dispatch - no go for %s (cc is %s)" % (event.auth or event.userhost, execstr))
result = None
View
1  jsb/plugs/core/more.py
@@ -25,6 +25,7 @@ def handle_more(bot, ievent):
if not txt:
ievent.reply('no more data available for %s' % target)
return
+ txt = bot.outputmorphs.do(txt, ievent)
if size: txt += "<b> - %s more</b>" % str(size)
bot.outnocb(target, txt, response=ievent.response)
bot.outmonitor(ievent.origin or ievent.userhost, ievent.channel, txt)
View
2  jsb/plugs/core/reload.py
@@ -31,7 +31,7 @@ def handle_reload(bot, ievent):
modname = bot.plugs.getmodule(plug)
if not modname: errors.append("can't find %s plugin" % plug) ; continue
try:
- loaded = bot.plugs.loaddeps(modname, force=True, showerror=True)
+ loaded = bot.plugs.reload(modname, force=True, showerror=True)
for plug in loaded:
reloaded.append(plug)
logging.warn("reload - %s reloaded" % plug)
View
0  jsb/plugs/common/dns.py → jsb/plugs/socket/dns.py
File renamed without changes
View
75 jsb/plugs/socket/geo.py
@@ -0,0 +1,75 @@
+# jsb/plugs/common/geo.py
+#
+#
+
+""" This product includes GeoLite data created by MaxMind, available from http://maxmind.com/ """
+
+
+## jsb imports
+
+from jsb.lib.callbacks import callbacks
+from jsb.lib.commands import cmnds
+from jsb.utils.url import geturl2
+from jsb.imports import getjson
+
+## system imports
+from socket import gethostbyname
+import re
+## defines
+
+URL = "http://geoip.pidgets.com/?ip=%s&format=json"
+
+def querygeoipserver(ip):
+ ipinfo = getjson().loads(geturl2(URL % ip))
+ return ipinfo
+
+def host2ip(query):
+ ippattern = re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", query)
+ hostpattern = re.match(r"(\w+://)?(?P<hostname>\S+\.\w+)", query)
+ ip = ""
+ if ippattern: ip = ippattern.group(0)
+ elif hostpattern:
+ try: ip = gethostbyname(hostpattern.group('hostname'))
+ except: pass
+ return ip
+
+## geo command
+
+def handle_geo(bot, event):
+ """ do a geo lookup. """
+ if not event.rest:
+ event.missing("<ip>")
+ return
+ query = event.rest.strip()
+ ip = host2ip(query)
+ if not ip: event.reply("Couldn't look up the hostname") ; return
+ event.reply("geo of %s is: " % ip, querygeoipserver(ip))
+
+cmnds.add("geo", handle_geo, ["OPER", "GEO"])
+
+def handle_geoPRE(bot, event):
+ if "." in event.hostname and event.chan.data.dogeo: return True
+
+def handle_geoJOIN(bot, event):
+ event.reply("geo - doing query on %s" % event.hostname)
+ result = querygeoipserver(host2ip(event.hostname))
+ if result: event.reply("geo info: ", result)
+ else: event.reply("no result")
+
+callbacks.add("JOIN", handle_geoJOIN, handle_geoPRE)
+
+def handle_geoon(bot, event):
+ """ enable geo lookup on JOIN. """
+ event.chan.data.dogeo = True
+ event.chan.save()
+ event.done()
+
+cmnds.add("geo-on", handle_geoon, ["OPER"])
+
+def handle_geooff(bot, event):
+ """ disable geo lookup on JOIN. """
+ event.chan.data.dogeo = False
+ event.chan.save()
+ event.done()
+
+cmnds.add("geo-off", handle_geooff, ["OPER"])
View
10 jsb/utils/generic.py
@@ -162,6 +162,16 @@ def strippedtxt(what, allowed=[]):
if ord(i) > 31 or (allowed and i in allowed): txt.append(i)
return ''.join(txt)
+## stripcolor function
+
+REcolor = re.compile(r"\003\d+(.+?)\003")
+
+def matchcolor(match):
+ return match.group(1)
+
+def stripcolor(txt):
+ return REcolor.sub(matchcolor, txt)
+
## uniqlist function
def uniqlist(l):
View
2  jsb/utils/lazydict.py
@@ -31,7 +31,7 @@
## defines
jsontypes = [types.StringType, types.UnicodeType, types.DictType, types.ListType, types.IntType]
-defaultignore = ['waitlist', 'comments', 'createdfrom', 'modname', 'cfile', 'dir', 'filename', 'webchannels', 'tokens', 'token', 'cmndperms', 'gatekeeper', 'stanza', 'isremote', 'iscmnd', 'orig', 'bot', 'origtxt', 'body', 'subelements', 'args', 'rest', 'cfg', 'pass', 'password', 'fsock', 'sock', 'handlers', 'users', 'plugins', 'outqueue', 'inqueue']
+defaultignore = ['finished', 'inqueue', 'resqueue', 'outqueue', 'waitlist', 'comments', 'createdfrom', 'modname', 'cfile', 'dir', 'filename', 'webchannels', 'tokens', 'token', 'cmndperms', 'gatekeeper', 'stanza', 'isremote', 'iscmnd', 'orig', 'bot', 'origtxt', 'body', 'subelements', 'args', 'rest', 'cfg', 'pass', 'password', 'fsock', 'sock', 'handlers', 'users', 'plugins']
cpy = copy.deepcopy
## checkignore function

No commit comments for this range

Something went wrong with that request. Please try again.