Beispiel #1
0
    def handle_join(self, ievent):
        """ handle joins. """

        if ievent.nick in self.nicks401:
            rlog(10, self.name, "%s is available again" % ievent.nick)
            self.nicks401.remove(ievent.nick)
        chan = ievent.channel.lower()
        nick = ievent.nick.lower()

        # see if its the bot who is joining
        if nick == self.nick.lower():
            # check if we already have a channels object, if not init it
            if not self.channels.has_key(chan):
                self.channels[chan] = {}
                self.channels[chan]['cc'] = self.cfg['defaultcc'] or '!'
            if not chan in self.state['joinedchannels']:
                self.state['joinedchannels'].append(chan)
                self.state.save()
            if chan in self.state['opchan']:
                self.state['opchan'].remove(chan)
                self.state.save()
            time.sleep(0.5)
            periodical.addjob(10, 1, self.who, self, chan)
            return

        # sync joined user with userhosts cache
        self.userhosts[nick] = ievent.userhost
        self.userchannels.adduniq(nick, chan)
Beispiel #2
0
    def handle_join(self, ievent):

        """ handle joins. """

        if ievent.nick in self.nicks401:
             rlog(10, self.name, "%s is available again" % ievent.nick)
             self.nicks401.remove(ievent.nick)
        chan = ievent.channel.lower()
        nick = ievent.nick.lower()

        # see if its the bot who is joining
        if nick == self.nick.lower():
            # check if we already have a channels object, if not init it
            if not self.channels.has_key(chan):
                self.channels[chan] = {}
                self.channels[chan]['cc'] = self.cfg['defaultcc'] or '!'
            if not chan in self.state['joinedchannels']:
                self.state['joinedchannels'].append(chan)
                self.state.save()
            if chan in self.state['opchan']:
                self.state['opchan'].remove(chan)
                self.state.save()
            time.sleep(0.5)
            periodical.addjob(10, 1, self.who, self, chan)
            return

        # sync joined user with userhosts cache
        self.userhosts[nick] = ievent.userhost
        self.userchannels.adduniq(nick, chan)
Beispiel #3
0
    def handle_001(self, ievent):

        """ we are connected.  """

        self.connectok.set()
        self.connected = True
        periodical.addjob(15, 1, self.whois, self, self.nick)
Beispiel #4
0
    def _resume(self, data, reto):
        """ resume the bot. """

        if not Irc._resume(self, data, reto):
            return 0
        for i in self.state['joinedchannels']:
            periodical.addjob(15, 1, self.who, self, i)
        return 1
Beispiel #5
0
    def _resume(self, data, reto):

        """ resume the bot. """

        if not Irc._resume(self, data, reto):
            return 0
        for i in self.state['joinedchannels']:
            periodical.addjob(15, 1, self.who, self, i)
        return 1
Beispiel #6
0
    def __init__(self, fname):
        Persist.__init__(self, fname)
        if not self.data:
            self.data = []
        for i in self.data:
            z = Alarmitem(d=i)
            try:
                getattr(z, 'printto')
            except AttributeError:
                setattr(z, 'printto', "")
            periodical.addjob(z.time - time.time(), 1, self.alarmsay, z.nick, \
z)
Beispiel #7
0
def init():
    global perm, db

    perm = 'USER'

    db = {}
    db['file'] = datadir + os.sep + name + '.sqlite'
    db['url'] = "http://ams-9.net/data/" + name + '.sqlite'
    db['refresh'] = 86400

    # read config
    if config[name + '_perm']:
        perm = config[name + '_perm']

    rlog(10, name, 'perm set to: %s' % perm)

    if config[name + '_database']:
        db['file'] = config[name + '_database']

    rlog(10, name, 'database set to: %s' % db['file'])

    # update the database
    if not os.path.exists(db['file']):
        db['age'] = ''
    else:
        age = os.stat(db['file'])[ST_MTIME]
        db['age'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
                                  time.gmtime(age))

    fetch_database()
    db['jid'] = periodical.addjob(db['refresh'], 0, fetch_database, name)

    # register commands
    cmnds.add("route", handle_addr, perm)
    examples.add("route", 'lookup an IP', name + ' 66.66.66.66')
Beispiel #8
0
    def add(self, botname, nick, ttime, txt, printto=None):
        """ add alarm """
        nick = nick.lower()
        nrid = nextid.next('alarms')
        item = Alarmitem(botname, nrid, nick, ttime, txt, printto=printto)
        pid = periodical.addjob(ttime - time.time(), 1, self.alarmsay, nick, \
item)
        item.idnr = pid
        self.data.append(item)
        self.save()
        return pid
def shutdown():
    periodical.kill()


def gcollect():
    rlog(1, 'gcollect', 'running collector')
    gc.collect()
    time.sleep(5)
    gc.collect()
    time.sleep(5)
    gc.collect()


if state['enable']:
    pid = periodical.addjob(state['wait'], 0, gcollect)
else:
    pid = None


def handle_gcollectwait(bot, ievent):
    try:
        newwait = int(ievent.args[0])
    except (IndexError, ValueError):
        ievent.reply('gcollect wait is %s seconds' % state['wait'])
        return
    if newwait < 60:
        ievent.reply('min. number of seconds is 60')
        return
    state['wait'] = newwait
    state.save()
Beispiel #10
0
    gc.enable()
    rlog(10, 'gcollect', 'garbage collector enabled .. wait is %s' % state['wait'])

def shutdown():
    periodical.kill()

def gcollect():
    rlog(1, 'gcollect', 'running collector')
    gc.collect()
    time.sleep(5)
    gc.collect()
    time.sleep(5)
    gc.collect()

if state['enable']:
    pid = periodical.addjob(state['wait'], 0, gcollect)
else:
    pid = None

def handle_gcollectwait(bot, ievent):
    try:
        newwait = int(ievent.args[0])
    except (IndexError, ValueError):
        ievent.reply('gcollect wait is %s seconds' % state['wait'])
        return
    if newwait < 60:
        ievent.reply('min. number of seconds is 60')
        return
    state['wait'] = newwait
    state.save()
    if pid:
Beispiel #11
0
    def watch(self, name):
        """ start a watcher thread """
        # get basic data
        rlog(10, "rss", "trying %s rss feed watcher" % name)
        try:
            result = self.getdata(name)
        except RssException, ex:
            rlog(10, "rss", "%s error: %s" % (name, str(ex)))
            result = []
        rssitem = self.byname(name)
        if not rssitem:
            raise RssNoItem()
        # poll every sleeptime seconds
        self.results[name] = result
        pid = periodical.addjob(rssitem.sleeptime, 0, self.peek, name, name)
        self.jobids[name] = pid
        rlog(10, "rss", "started %s rss watch" % name)

    def makeresponse(self, name, res, channel, sep="\002||\002"):
        # loop over result to make a response
        result = ""
        itemslist = self.itemslists[(name, channel)]
        if not itemslist:
            rssitem = self.byname(name)
            if not rssitem:
                return "no %s rss item" % name
            else:
                self.itemslists.extend((name, channel), rssitem.itemslist)
                self.itemslists.save()
        for j in res:
Beispiel #12
0
 def start(self):
     self.pid = periodical.addjob(cfg.get('sleep'), 0, self.peek,
                                  'httpwatch', 'httpwatch')
def handle_gcollectenable(bot, ievent):
    global pid
    state['enable'] = 1
    state.save()
    pid = periodical.addjob(state['wait'], 0, gcollect)
    ievent.reply('gcollect enabled')
Beispiel #14
0
    def watch(self, name):
        """ start a watcher thread """
        # get basic data
        rlog(10, 'rss', 'trying %s rss feed watcher' % name)
        try:
            result = self.getdata(name)
        except RssException, ex:
            rlog(10, 'rss', "%s error: %s" % (name, str(ex)))
            result = []
        rssitem = self.byname(name)
        if not rssitem:
            raise RssNoItem()
        # poll every sleeptime seconds
        self.results[name] = result
        pid = periodical.addjob(rssitem.sleeptime, 0, self.peek, name, name)
        self.jobids[name] = pid
        rlog(10, 'rss', 'started %s rss watch' % name)

    def makeresponse(self, name, res, channel, sep="\002||\002"):
        # loop over result to make a response
        result = ""
        itemslist = self.itemslists[(name, channel)]
        if not itemslist:
            rssitem = self.byname(name)
            if not rssitem:
                return "no %s rss item" % name
            else:
                self.itemslists.extend((name, channel), rssitem.itemslist)
                self.itemslists.save()
        for j in res:
Beispiel #15
0
def handle_gcollectenable(bot, ievent):
    global pid
    state['enable'] = 1
    state.save()
    pid = periodical.addjob(state['wait'], 0, gcollect)
    ievent.reply('gcollect enabled')
Beispiel #16
0
    def handle_001(self, ievent):
        """ we are connected.  """

        self.connectok.set()
        self.connected = True
        periodical.addjob(15, 1, self.whois, self, self.nick)
Beispiel #17
0
 def start(self):
     self.pid = periodical.addjob(cfg.get('sleep'), 0, self.peek, 'httpwatch', 'httpwatch')