Example #1
0
from jsb.lib.aliases import setalias
from jsb.lib.config import getmainconfig
from jsb.lib.plugins import plugs
from jsb.db import getmaindb

## basic imports

import time
import thread
import os
import logging

## locks

todolock = thread.allocate_lock()
locked = lockdec(todolock)

## defines

db = None

## TodoItem class


class TodoItem:
    """ a todo item """
    def __init__(self,
                 name,
                 descr,
                 ttime=None,
                 duration=None,
Example #2
0
from httplib import InvalidURL
from urlparse import urlparse
import socket
import asynchat
import urllib
import sys
import thread
import re
import asyncore
import time
import logging

## defines

restlock = thread.allocate_lock()
locked = lockdec(restlock)

## RestResult class

class RestResult(LazyDict):

    def __init__(self, url="", name=""):
        LazyDict.__init__(self)
        self.url = url
        self.name = name
        self.data = None
        self.error = None
        self.status = None
        self.reason = ""

## RestClient class
Example #3
0
import sys
import os
import types
import thread
import logging
import uuid
import thread
import getpass
import copy
import time

## locks

savelock = thread.allocate_lock()
savelocked = lockdec(savelock)

## defines

cpy = copy.deepcopy

## classes

class Config(LazyDict):

    """ 
        config class is a dict containing json strings. is writable to file 
        and human editable.

    """
Example #4
0
from jsb.utils.url import striphtml
from jsb.utils.format import formatevent, format_opt

## basic imports

import time
import os
import logging
import thread
from os import path
from datetime import datetime

## locks

outlock = thread.allocate_lock()
outlocked = lockdec(outlock)

## defines

cfg = PersistConfig()
cfg.define('channels', [])
cfg.define('format', 'log')
cfg.define('basepath', getdatadir())
cfg.define('nologprefix', '[nolog]')
cfg.define('nologmsg', '-= THIS MESSAGE NOT LOGGED =-')
cfg.define('backend', 'log')

logfiles = {}
backends = {}
stopped = False
db = None
Example #5
0
from jsb.utils.statdict import StatDict
from jsb.utils.timeutils import striptime, strtotime2

## basic imports

import time
import os
import logging
import thread
from os import path
from datetime import datetime

## locks

outlock = thread.allocate_lock()
outlocked = lockdec(outlock)

## defines

cfg = PersistConfig()
cfg.define('channels', [])
cfg.define('format', 'log')
cfg.define('basepath', getdatadir())
cfg.define('nologprefix', '[nolog]')
cfg.define('nologmsg', '-= THIS MESSAGE NOT LOGGED =-')
cfg.define('backend', 'log')

logfiles = {}
backends = {}
stopped = False
db = None
Example #6
0
from jsb.utils.statdict import StatDict
from jsb.lib.aliases import setalias

## basic imports

import thread
import pickle
import time
import os
import logging

## defines

ratelimited = []
limiterlock = thread.allocate_lock()
limlock = lockdec(limiterlock)

db = None

## KarmaDb class


class KarmaDb(object):
    """ karma object """
    def save(self):
        pass

    def size(self):
        """ return number of karma items """
        global db
        if not db:
Example #7
0
import os
import shutil
import thread
import logging
import types
import copy

## defines

cpy = copy.deepcopy
alarms = None

## locks

alarmlock = thread.allocate_lock()
alarmlocked = lockdec(alarmlock)

## Alarmitem class


class Alarmitem(LazyDict):
    """ item holding alarm data """
    def __init__(self,
                 botname='default',
                 i=0,
                 nick="",
                 ttime=time.time(),
                 txt="",
                 printto=None,
                 d={}):
        if not d: LazyDict.__init__(self)
Example #8
0
from httplib import InvalidURL
from urlparse import urlparse
import socket
import asynchat
import urllib
import sys
import thread
import re
import asyncore
import time
import logging

## defines

restlock = thread.allocate_lock()
locked = lockdec(restlock)

## RestResult class


class RestResult(LazyDict):
    def __init__(self, url="", name=""):
        LazyDict.__init__(self)
        self.url = url
        self.name = name
        self.data = None
        self.error = None
        self.status = None
        self.reason = ""

Example #9
0
    setalias('wq', 'quote2-who')
    setalias('dq', 'quote2-del')
    setalias('lq', 'quote2-last')
    setalias('2q', 'quote2-2')
    setalias('iq', 'quote2-id')
    setalias('q', 'quote2')
    setalias('sq', 'quote2-search')
    setalias('cq', 'quote2-count')
    setalias('q-good', 'quote2-good')
    setalias('q-bad', 'quote2-bad')


## locks

quoteslock = thread.allocate_lock()
locked = lockdec(quoteslock)

## QuoteItem class


class QuoteItem(object):
    """ object representing a quote """
    def __init__(self, idnr, txt, nick=None, userhost=None, ttime=None):
        self.id = idnr
        self.txt = txt
        self.nick = nick
        self.userhost = userhost
        self.time = ttime


## QuetesDb class
Example #10
0
from jsb.utils.locking import lockdec
from jsb.lib.callbacks import callbacks
from jsb.lib.users import getusers
from jsb.lib.config import getmainconfig

## basic imports

import thread
import os
import time
import logging

## locks

infolock = thread.allocate_lock()
locked = lockdec(infolock)

## defines

db = None

## InfoItemsDb class

class InfoItemsDb(object):

    """ information items """

    def add(self, item, description, userhost, ttime):
        """ add an item """
        if not db: logging.error("plugin isnt initialised yet") ; return []
        item = item.lower()
Example #11
0
from jsb.utils.locking import lockdec
from jsb.lib.callbacks import callbacks
from jsb.lib.users import getusers
from jsb.lib.config import getmainconfig

## basic imports

import thread
import os
import time
import logging

## locks

infolock = thread.allocate_lock()
locked = lockdec(infolock)

## defines

db = None

## InfoItemsDb class


class InfoItemsDb(object):
    """ information items """
    def add(self, item, description, userhost, ttime):
        """ add an item """
        if not db:
            logging.error("plugin isnt initialised yet")
            return []
Example #12
0
from jsb.utils.exception import handle_exception
from jsb.utils.locking import lockdec
from threads import start_new_thread

## basic imports

import Queue
import thread
import logging
import time

## locks

handlerlock = thread.allocate_lock()
locked = lockdec(handlerlock)

## classes


class EventHandler(object):
    """
        events are handled in 11 queues with different priorities:
        queue0 is tried first queue10 last.

    """
    def __init__(self):
        self.sortedlist = []
        try:
            self.queue = Queue.PriorityQueue()
        except AttributeError:
Example #13
0
from jsb.utils.lazydict import LazyDict
from jsb.imports import getjson

## basic imports

import logging
import thread

## defines

json = getjson()

## locks

parselock = thread.allocate_lock()
locked = lockdec(parselock)

## ConvoreEvent

class ConvoreEvent(EventBase):
    """ Convore Event."""

    def parse(self, bot, message, root):
        m = LazyDict(message)
        self.root = LazyDict(root)
        type = m.kind.replace("-", "_")
        self.type = type
        self.cbtype = "CONVORE"
        self.bottype = bot.type
        self.username = m.user['username']
        self.userhost = "%s_%s" % ("CONVORE_USER", self.username) 
Example #14
0
## basic imports

import logging
import copy
import os
import time
import re
import thread

## defines

findurl = re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\),\\\"]")
cpy = copy.deepcopy

saylock = thread.allocate_lock()
saylocked = lockdec(saylock)

## Wave class (channel)

class Wave(ChannelBase):

    """ a wave is seen as a channel. """

    def __init__(self, waveid, botname=None):
        ChannelBase.__init__(self, waveid, botname)
        self.data.seenblips = self.data.seenblips or 0
        self.data.threshold = self.data.threshold or -1
        self.data.nrcloned = self.data.nrcloned or 0
        self.data.waveid = waveid
        self.wavelet = None
        self.event = None
Example #15
0
from jsb.utils.statdict import StatDict
from jsb.lib.aliases import setalias

## basic imports

import thread
import pickle
import time
import os
import logging

## defines

ratelimited = []
limiterlock = thread.allocate_lock()
limlock = lockdec(limiterlock)

db = None

## KarmaDb class

class KarmaDb(object):

    """ karma object """

    def save(self):
        pass

    def size(self):
        """ return number of karma items """
        global db
Example #16
0
import thread
import types
import threading
import Queue
import re
import urllib
from collections import deque

## defines

cpy = copy.deepcopy

## locks

reconnectlock = threading.RLock()
reconnectlocked = lockdec(reconnectlock)

lock = thread.allocate_lock()
locked = lockdec(lock)

## classes

class BotBase(LazyDict):

    """ base class for all bots. """

    def __init__(self, cfg=None, usersin=None, plugs=None, botname=None, nick=None, bottype=None, nocbs=None, *args, **kwargs):
        logging.debug("type is %s" % str(type(self)))
        if cfg: self.cfg = cfg ; botname = botname or self.cfg.name
        if not botname: botname = u"default-%s" % str(type(self)).split('.')[-1][:-2]
        if not botname: raise Exception("can't determine  botname")
Example #17
0
import Queue
import time
import thread
import random
import logging
import sys

## defines

stats = StatDict()

## locks

startlock = thread.allocate_lock()
startlocked = lockdec(startlock)

## Runner class

class Runner(RunnerLoop):

    """
        a runner is a thread with a queue on which jobs can be pushed. 
        jobs scheduled should not take too long since only one job can 
        be executed in a Runner at the same time.

    """

    def __init__(self, name="runner", doready=True):
        RunnerLoop.__init__(self, name)
        self.working = False
Example #18
0
## jsb imports

from jsb.utils.exception import handle_exception
from jsb.utils.locking import lockdec
from threads import start_new_thread

## basic imports

import Queue
import thread

## locks

handlerlock = thread.allocate_lock()
locked = lockdec(handlerlock)

## classes

class EventHandler(object):

    """
        events are handled in 11 queues with different priorities:
        queue0 is tried first queue10 last.

    """

    def __init__(self):
        self.sortedlist = []
        self.queues = {}
        for i in range(11):
Example #19
0
from jsb.lib.eventbase import EventBase
from jsb.lib.errors import BotNotSetInEvent
from jsb.lib.gozerevent import GozerEvent

## basic imports

import types
import time
import thread
import logging
import re

## locks

replylock = thread.allocate_lock()
replylocked = lockdec(replylock)

## classes

class Message(GozerEvent):

    """ jabber message object. """

    def __init__(self, nodedict={}):
        self.element = "message"
        self.jabber = True
        self.cmnd = "MESSAGE"
        self.cbtype = "MESSAGE"
        self.bottype = "xmpp"
        self.type = "normal"
        self.speed = 8
Example #20
0
import Queue
import copy
import sys
import thread
import types
import time
from collections import deque

## defines

cpy = copy.deepcopy

## locks

loadlock = thread.allocate_lock()
locked = lockdec(loadlock)

## Plugins class

class Plugins(LazyDict):

    """ the plugins object contains all the plugins. """

    loading = LazyDict()

    def size(self): return len(self)

    def exit(self):
        todo = cpy(self)
        for plugname in todo:
            self.unload(plugname)         
Example #21
0
File: pdod.py Project: code2u/jsb
""" gozerbot compat pickled dicts of dicts. """

# jsb imports

from jsb.utils.locking import lockdec
from jsb.compat.persist import Persist

## basic imports

import thread

## locks

pdodlock = thread.allocate_lock()
locked = lockdec(pdodlock)

## Pdod class


class Pdod(Persist):

    """ pickled dicts of dicts """

    def __init__(self, filename):
        Persist.__init__(self, filename)
        if not self.data:
            self.data = {}

    def __getitem__(self, name):
        """ return item with name """
Example #22
0
    setalias('wq', 'quote2-who')
    setalias('dq', 'quote2-del')
    setalias('lq', 'quote2-last')
    setalias('2q', 'quote2-2')
    setalias('iq', 'quote2-id')
    setalias('q', 'quote2')
    setalias('sq', 'quote2-search')
    setalias('cq', 'quote2-count')
    setalias('q-good', 'quote2-good')
    setalias('q-bad', 'quote2-bad')


## locks

quoteslock = thread.allocate_lock()
locked = lockdec(quoteslock)

## QuoteItem class

class QuoteItem(object):

    """ object representing a quote """

    def __init__(self, idnr, txt, nick=None, userhost=None, ttime=None):
        self.id = idnr
        self.txt = txt
        self.nick = nick
        self.userhost = userhost
        self.time = ttime

## QuetesDb class
Example #23
0
## xmpp import

from jsb.contrib.xmlstream import NodeBuilder, XMLescape, XMLunescape

## basic imports

import types
import time
import thread
import logging
import re

## locks

replylock = thread.allocate_lock()
replylocked = lockdec(replylock)

## classes


class Message(GozerEvent):
    """ jabber message object. """
    def __init__(self, nodedict={}):
        self.element = "message"
        self.jabber = True
        self.cmnd = "MESSAGE"
        self.cbtype = "MESSAGE"
        self.bottype = "xmpp"
        self.type = "normal"
        GozerEvent.__init__(self, nodedict)
Example #24
0
## gozerbot imports

from jsb.utils.locking import lockdec
import jsb.lib.threads as thr

## basic imports

import time
import thread
import logging

## locks

waitlock = thread.allocate_lock()
locked = lockdec(waitlock)

## classes

class Wait(object):

    """ lists of ircevents to wait for """

    def __init__(self):
        self.waitlist = []
        self.ticket = 0

    def register(self, cmnd, catch, queue, timeout=15):
        """ register wait for cmnd. """
        logging.debug('irc - wait - registering for cmnd ' + cmnd)
        self.ticket += 1
Example #25
0
import Queue
import copy
import sys
import thread
import types
import time
from collections import deque

## defines

cpy = copy.deepcopy

## locks

loadlock = thread.allocate_lock()
locked = lockdec(loadlock)

## Plugins class


class Plugins(LazyDict):
    """ the plugins object contains all the plugins. """

    loading = LazyDict()

    def size(self):
        return len(self)

    def exit(self):
        todo = cpy(self)
        for plugname in todo:
Example #26
0
from jsb.lib.persist import PlugPersist
from jsb.lib.persiststate import UserState
from jsb.utils.lazydict import LazyDict

## basic imports

import time
import thread
import os
from datetime import datetime, timedelta
from time import localtime

## defines

todolock = thread.allocate_lock()
locked = lockdec(todolock)

class Todo(LazyDict):
    pass

class TodoList(UserState):

    def __init__(self, name, *args, **kwargs):
        UserState.__init__(self, name, "todo", *args, **kwargs)
        if self.data.list:
            self.data.list = [LazyDict(x) for x in self.data.list]
        else:
            self.data.list = []

    def add(self, txt, ttime=0, duration=0, warnsec=0, priority=0):
        """ add a todo """
Example #27
0
from jsb.lib.callbacks import callbacks
import jsb.lib.threads as thr

## basic imorts

import datetime
import sys
import time
import thread
import types
import logging

## locks

plock    = thread.allocate_lock()
locked   = lockdec(plock)

## defines

pidcount = 0

## JobError class

class JobError(Exception):

    """ job error exception. """
    pass

## Job class

class Job(object):
Example #28
0
import sys
import base64
import random

## python 2.5 shim

try: bytes()
except:
    def bytes(txt): return str(txt)    

## locks

outlock = thread.allocate_lock()   
inlock = thread.allocate_lock()
connectlock = thread.allocate_lock()
outlocked = lockdec(outlock)
inlocked = lockdec(inlock)  
connectlocked = lockdec(connectlock) 

## classes

class XMLStream(xmlstream.NodeBuilder):

    """ XMLStream. """

    def __init__(self, name=None):
        if not self.cfg: raise Exception("sxmpp - config is not set")
        self.cfg.name = name or self.cfg.name
        if not self.cfg.name: raise Exception("bot name is not set in config file %s" % self.cfg.filename)
        self.connection = None
        self.target = None
Example #29
0
import os
import shutil
import thread
import logging
import types
import copy

## defines

cpy = copy.deepcopy
alarms = None

## locks

alarmlock = thread.allocate_lock()
alarmlocked = lockdec(alarmlock)

## Alarmitem class

class Alarmitem(LazyDict):

    """ item holding alarm data """

    def __init__(self, botname='default', i=0, nick="", ttime=time.time(), txt="", printto=None, d={}):
        if not d: LazyDict.__init__(self)
        else: LazyDict.__init__(self, d)
        self.botname = self.botname or botname
        self.idnr = self.idnr or i
        self.nick = self.nick or nick
        self.time = self.ttime or ttime
        self.txt = self.txt or txt
Example #30
0
import Queue
import time
import thread
import random
import logging
import sys

## defines

stats = StatDict()

## locks

startlock = thread.allocate_lock()
startlocked = lockdec(startlock)

## Runner class


class Runner(RunnerLoop):
    """
        a runner is a thread with a queue on which jobs can be pushed. 
        jobs scheduled should not take too long since only one job can 
        be executed in a Runner at the same time.

    """
    def __init__(self, name="runner", doready=True):
        RunnerLoop.__init__(self, name)
        self.working = False
        self.starttime = time.time()
Example #31
0
import thread
import types
import threading
import Queue
import re
import urllib
from collections import deque

## defines

cpy = copy.deepcopy

## locks

reconnectlock = threading.RLock()
reconnectlocked = lockdec(reconnectlock)

lock = thread.allocate_lock()
locked = lockdec(lock)

## classes


class BotBase(LazyDict):
    """ base class for all bots. """
    def __init__(self,
                 cfg=None,
                 usersin=None,
                 plugs=None,
                 botname=None,
                 nick=None,
Example #32
0
from jsb.lib.callbacks import callbacks
import jsb.lib.threads as thr

## basic imorts

import datetime
import sys
import time
import thread
import types
import logging

## locks

plock = thread.allocate_lock()
locked = lockdec(plock)

## defines

pidcount = 0

## JobError class


class JobError(Exception):
    """ job error exception. """
    pass


## Job class
Example #33
0
from jsb.utils.generic import tolatin1
from jsb.utils.exception import handle_exception
from jsb.lib.datadir import getdatadir

## basic imports

import thread
import os
import time
import types
import logging

## locks

dblock = thread.allocate_lock()
dblocked = lockdec(dblock)

## Db class

class Db(object):

    """ this class implements a database connection. it connects to the 
        database on initialisation.
    """

    def __init__(self, dbname=None, dbhost=None, dbuser=None, dbpasswd=None, dbtype=None, ddir=None, doconnect=True):
        self.datadir = ddir or getdatadir()
        self.datadir = self.datadir + os.sep + "db" + os.sep
        if hasattr(os, 'mkdir'):
            if not os.path.isdir(self.datadir):
                try: os.mkdir(self.datadir)
Example #34
0
import copy

## defines

cpy = copy.deepcopy

## classes

class FleetBotAlreadyExists(Exception):
    pass

## locks

from jsb.utils.locking import lockdec
lock = thread.allocate_lock()
locked = lockdec(lock)

## Fleet class

class Fleet(Persist):

    """
        a fleet contains multiple bots (list of bots).

    """

    def __init__(self, datadir):
        Persist.__init__(self, datadir + os.sep + 'fleet' + os.sep + 'fleet.main')
        if not self.data.has_key('names'): self.data['names'] = []
        if not self.data.has_key('types'): self.data['types'] = {}
        self.startok = threading.Event()
Example #35
0
from jsb.utils.generic import tolatin1
from jsb.utils.exception import handle_exception
from jsb.lib.datadir import getdatadir

## basic imports

import thread
import os
import time
import types
import logging

## locks

dblock = thread.allocate_lock()
dblocked = lockdec(dblock)

## Db class


class Db(object):
    """ this class implements a database connection. it connects to the 
        database on initialisation.
    """
    def __init__(self,
                 dbname=None,
                 dbhost=None,
                 dbuser=None,
                 dbpasswd=None,
                 dbtype=None,
                 ddir=None,