示例#1
0
# plugs/url.py
#
#

from gozerbot.generic import handle_exception, rlog, convertpickle
from gozerbot.callbacks import callbacks
from gozerbot.commands import cmnds
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
from gozerbot.datadir import datadir
from gozerbot.persist.persiststate import PlugState
import re, os

plughelp.add('url', 'maintain searchable logs of urls')


def upgrade():
    convertpickle(datadir + os.sep + 'old' + os.sep + 'url', \
datadir + os.sep + 'plugs' + os.sep + 'url' + os.sep + 'state')


re_url_match = re.compile(u'((?:http|https)://\S+)')
state = None


def init():
    global state
    state = PlugState()
    state.define('urls', {})
    return 1
示例#2
0
__gendoclast__ = ['part', ]

# gozerbot imports
from gozerbot.callbacks import callbacks
from gozerbot.fleet import fleet
from gozerbot.partyline import partyline
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests
import gozerbot.threads.thr as thr

# basic imports
import Queue, sets

plughelp.add('irc', 'irc related commands')

ignorenicks = []

def handle_broadcast(bot, ievent):

    """ broadcast txt to all joined channels. """

    if not ievent.rest:
         ievent.missing('<txt>')
         return

    fleet.broadcast(ievent.rest)
    partyline.say_broadcast(ievent.rest)

cmnds.add('broadcast', handle_broadcast, 'OPER')
示例#3
0
from gozerbot.generic import handle_exception, rlog, strtotime, striptime, \
jsonstring
from gozerbot.utils.lazydict import LazyDict
from gozerbot.persist.persist import Persist
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.utils.nextid import nextid
from gozerbot.fleet import fleet
from gozerbot.datadir import datadir
from gozerbot.plughelp import plughelp
from gozerbot.aliases import aliases
from gozerbot.periodical import periodical
from gozerbot.tests import tests
import time, os, shutil

plughelp.add('alarm', 'remind the user with given txt at a certain time')

## UPGRADE PART

def upgrade():
    pass

## END UPGRARE PART

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:
示例#4
0
# gozerbot/plugs/inform.py
#
#
""" prepend nick: to the output of a command. """

# gozerbot imports
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plugins import plugins
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

plughelp.add('inform', 'inform <nick> the output of a command')


def handle_inform(bot, ievent):
    """ prepend nick: to the output of command to another user """
    if ievent.msg:
        ievent.reply('inform can only be used in a channel')
        return

    try:
        nick, cmnd = ievent.rest.split(' ', 1)
    except ValueError:
        ievent.missing('<nick> <command>')
        return

    ievent.txt = cmnd
    result = plugins.cmnd(bot, ievent)

    if not result:
示例#5
0
#
#

""" eight ball """

__copyright__ = 'this file is in the public domain'
__revision__ = '$Id: m8b.py 1120 2006-12-30 12:00:00Z deck $'

from gozerbot.generic import handle_exception
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests
import re, random

plughelp.add('8b', 'Ask the magic 8 ball')

balltxt=[
    "Signs point to yes.",
    "Yes.",
    "Most likely.",
    "Without a doubt.",
    "Yes - definitely.",
    "As I see it, yes.",
    "You may rely on it.",
    "Outlook good.",
    "It is certain.",
    "It is decidedly so.",
    "Reply hazy, try again.",
    "Better not tell you now.",
    "Ask again later.",
示例#6
0
            for z in j:
                karma.setwhodown(i, z)

        for i, j in k.whoup.iteritems():
            for z in j:
                karma.setwhoup(i, z)
    except Exception, ex:
        rlog(10, 'karma', 'failed to upgrade: %s' % str(ex))
        return
    rlog(10, 'karma', 'upgraded %s karma items' % str(teller))


# END UPGRADE PART

plughelp.add(
    'karma', 'maintain karma of items .. use ++ to raise karma by 1 \
or use -- to lower by 1 .. reason might be given after a "#"')


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

    def size(self):
        """ return number of items """
        s = create_session()
        count = s.query(sa.func.count(Karma.item)).first()[0]
        return count

    @trans
示例#7
0
#
#
""" ignore users. """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.commands import cmnds
from gozerbot.generic import getwho
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.ignore import addignore, delignore, ignore
from gozerbot.tests import tests
from gozerbot.users import users

plughelp.add('ignore', 'ignore users for a certain time')


def handle_ignore(bot, ievent):
    """ ignore nick for number of seconds. """

    try:
        (nick, nrseconds) = ievent.args
        nrseconds = int(nrseconds)
    except ValueError:
        ievent.missing('<nick> <seconds>')
        return

    userhost = getwho(bot, nick)

    if not userhost:
示例#8
0
# plugs/tel.py
#
#

""" telefone codes """

__copyright__ = 'this file is in the public domain'

from gozerbot.generic import geturl, striphtml, splittxt
from gozerbot.commands import cmnds
from gozerbot.aliases import aliases
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
import re, random

plughelp.add('tel', 'show country telephone codes')

codes = [
	("213", "ALGERIA", "DZ"),
	("102", "ANTIGUA BARBUDA", ""),
	("54", "ARGENTINA", "AR"),
	("374", "ARMENIA", "AM"),
	("297", "ARUBA", "AW"),
	("61", "AUSTRALIA", "AU"),
	("43", "AUSTRIA", "AT"),
	("994", "AZERBAIJAN", "AZ"),
	("103", "BAHAMAS", "BS"),
	("104", "BARBADOS", "BB"),
	("375", "BELARUS", "BY"),
	("32", "BELGIUM", "BE"),
	("105", "BERMUDA", "BM"),
示例#9
0
# plugs/dns.py
#
# 

__copyright__ = 'this file is in the public domain'

from gozerbot.commands import cmnds
from gozerbot.examples import examples 
from gozerbot.plughelp import plughelp
import copy
import re
import socket

plughelp.add('dns', 'do ip or host lookup')

_re_hexip = re.compile('^[\da-f]{8}$', re.I)

def handle_hostname(bot, ievent):
    """ hostname <ipnr> .. get hostname of ip number"""
    try:
        item = ievent.args[0]
    except IndexError:
        ievent.missing('<ipnr>')
        return
    try:
        hostname = socket.gethostbyaddr(item)
        ievent.reply(hostname[0])
    except:
        ievent.reply("can't match " + str(item))

cmnds.add('host', handle_hostname, 'USER')
示例#10
0
#
# Sorting

""" sort bot results. """

__author__ = "Wijnand 'maze' Modderman <http://tehmaze.com>"
__license__ = "BSD"

from gozerbot.commands import cmnds
from gozerbot.generic import waitforqueue
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
from gozerbot.tests import tests
import optparse

plughelp.add('sort', ' sort elements (of a pipeline)')

class SortError(Exception): pass

class SortOptionParser(optparse.OptionParser):
    def __init__(self):
        optparse.OptionParser.__init__(self)
        self.add_option('-f', '--ignore-case',
            help='fold lower case to upper case characters', default=False,
            action='store_true', dest='ignorecase')
        self.add_option('-n', '--numeric-sort', default=False,
            help='compare according to string numerical value', 
            action='store_true', dest='numeric')
        self.add_option('-r', '--reverse', default=False,
            help='reverse the result of comparisons', 
            action='store_true', dest='reverse')
示例#11
0
from gozerbot.generic import rlog, geturl, striphtml, jsonstring
from gozerbot.persist.persist import PlugPersist
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.callbacks import callbacks, jcallbacks
from gozerbot.plughelp import plughelp
from gozerbot.plugins import plugins
from gozerbot.threads.thr import start_new_thread
from gozerbot.utils.statdict import Statdict
from gozerbot.utils.limlist import Limlist
from os.path import join as _j
import time, re, random, types

from gozerbot.persist.persistconfig import PersistConfig

plughelp.add('markov', 'Gozerbot speaking madness')

cfg = PersistConfig()
cfg.define('enable', [])
cfg.define('command', 1)
cfg.define('onjoin', [])

def enabled(botname, channel):
    if jsonstring([botname, channel]) in cfg['enable']:
        return True

# Markers (is Marker the correct name for this?)
class Marker: pass
class BeginMarker(Marker): pass
class EndMarker(Marker): pass
class NickMarker(Marker): pass
示例#12
0
__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
__license__ = 'BSD'
__depending__ = ['rss', ]

from gozerbot.aliases import aliases
from gozerbot.callbacks import callbacks
from gozerbot.commands import cmnds
from gozerbot.generic import striphtml, useragent, rlog
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
import urllib
import urllib2
import urlparse
import re

plughelp.add('tinyurl', 'the tinyurl url provides a tiny url for the url \
provided as argument or the last url in the log')

re_url_match  = re.compile(u'((?:http|https)://\S+)')
urlcache = {}

def valid_url(url):
    """ check if url is valid """
    if not re_url_match.search(url):
        return False
    parts = urlparse.urlparse(url)
    cleanurl = '%s://%s' % (parts[0], parts[1])
    if parts[2]:
        cleanurl = '%s%s' % (cleanurl, parts[2])
    if parts[3]:
        cleanurl = '%s;%s' % (cleanurl, parts[3])
    if parts[4]:
示例#13
0
# plugs/drinks.py
#
#

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
import os, string, random

plughelp.add('drinks', 'serve coffee/tea or beer')

coffee = []
tea = []
beer = []


def init():
    global coffee
    global tea
    global beer
    for i in coffeetxt.split('\n'):
        if i:
            coffee.append(i.strip())
    for i in teatxt.split('\n'):
        if i:
            tea.append(i.strip())
    for i in beertxt.split('\n'):
        if i:
            beer.append(i.strip())
    return 1
示例#14
0
from gozerbot.generic import useragent, waitforqueue
from gozerbot.plughelp import plughelp
from gozerbot.persist.persistconfig import PersistConfig
import copy
import optparse
import urllib
import urllib2

cfg = PersistConfig()
cfg.define('url', 'http://www.paste-it.net/ajax/pit/')
cfg.define('expiry', 604800)
cfg.define('items', 50)
cfg.define('waitforqueue', 50)
cfg.define('useragent', 'paste-it.net command line client (Compatible; %s)' % ' '.join(config['version'].split()[0:2]))

plughelp.add('pit', 'http://www.paste-it.net paste functionality')

class PitOptionParser(optparse.OptionParser):
    def __init__(self, ievent):
        optparse.OptionParser.__init__(self)
        self.ievent = ievent
        self.ievent.stop = False
        self.formatter = optparse.IndentedHelpFormatter(0, 24, None, 1)
        self.formatter.set_parser(self)

    # no wai!
    def exit(self, status=0, msg=None):
        pass

    def error(self, msg):
        if msg:
示例#15
0
#
""" negative grep. """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.tests import tests
from gozerbot.examples import examples
from gozerbot.commands import cmnds
from gozerbot.generic import waitforqueue
from gozerbot.plughelp import plughelp

# basic imports
import getopt, re

plughelp.add('not', 'the not command is a negative grep used in pipelines')


def handle_not(bot, ievent):
    """ negative grep. """

    if not ievent.inqueue:
        ievent.reply('use not in a pipeline')
        return

    if not ievent.rest:
        ievent.reply('not <txt>')
        return

    try:
        (options, rest) = getopt.getopt(ievent.args, 'r')
示例#16
0
__license__ = "BSD"

# gozerbot imports
from gozerbot.aliases import aliases
from gozerbot.commands import cmnds
from gozerbot.periodical import periodical, at
from gozerbot.plugins import plugins
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.generic import uniqlist
from gozerbot.tests import tests

# basic imports
import copy, datetime, time, types

plughelp.add('job', 'job management')

def size():

    """ show nr of running jobs. """

    return len(periodical.jobs)

def handle_job(bot, ievent):

    """ show data of <jobid>. """

    if not ievent.args or not ievent.args[0].isdigit():
        ievent.reply('<job id>')
        return
示例#17
0
# IP subnet calculator
# (c) 2007 Wijnand 'tehmaze' Modderman - http://tehmaze.com
# BSD License

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp

plughelp.add('ipcalc', 'ip calculator')


# IP subnet calculator
# (C) 2007 Wijnand 'tehmaze' Modderman - http://tehmaze.com
# BSD License
#
# ABOUT
#  This module allows you to perform network calculations.
#
# CHANGELOG
#  2007-10-26: Added IPv6 support, as well as a lot of other functions, 
#              refactored the calculations.
#  2007-10-25: Initial writeup, because I could not find any other workable
#              implementation.
#
# TODO
#  * add CLI parser
#
# REFERENCES
#  * http://www.estoile.com/links/ipv6.pdf
#  * http://www.iana.org/assignments/ipv4-address-space
#  * http://www.iana.org/assignments/multicast-addresses
示例#18
0
# gozerplugs/plugs/powernick.py
#
#

""" relay log messages to nicks joined on the partyline (DCC CHAT) """

from gozerbot.callbacks import callbacks
from gozerbot.persist.persiststate import PlugState
from gozerbot.commands import cmnds
from gozerbot.users import users
from gozerbot.examples import examples
from gozerbot.partyline import partyline
from gozerbot.plughelp import plughelp
import gozerbot.generic

plughelp.add('powernick', 'plugin used to monitor log messages')

state = PlugState()
state.define('nicks', {}) # username is key


def logcallback(level, description, txt):
    global state
    for nick in state['nicks'].values():
        partyline.say_nick(nick, "[%s] %s" % (description, txt)) 

def init():
    if not logcallback in gozerbot.utils.log.logcallbacks:
        gozerbot.utils.log.logcallbacks.append(logcallback)

def shutdown():
示例#19
0
from gozerbot.fleet import fleet
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.datadir import datadir
from gozerbot.utils.dol import Dol
from gozerbot.compat.pdod import Pdod
from gozerbot.compat.pdol import Pdol
from gozerbot.plughelp import plughelp
from gozerbot.periodical import periodical
from gozerbot.aliases import aliasset
from gozerbot.users import users
import feedparser
import gozerbot.threads.thr as thr
import time, os, types, thread, socket, xml

plughelp.add('rss', 'manage rss feeds')

savelist = []


def txtindicts(result, d):
    """ return lowlevel values in (nested) dicts """
    for j in d.values():
        if type(j) == types.DictType:
            txtindicts(result, j)
        else:
            result.append(j)


def checkfordate(data, date):
    for item in data:
示例#20
0
#
""" code related commands. """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.redispatcher import rebefore, reafter
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.generic import exceptionlist
from gozerbot.plugins import plugins
from gozerbot.aliases import aliasset
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

plughelp.add('code', 'the code plugin provides code related commands')


def handle_showexceptions(bot, ievent):
    """ show exception list. """

    ievent.reply(str(exceptionlist))


cmnds.add('code-exceptions', handle_showexceptions, 'OPER')
examples.add('code-exceptions', 'show exception list', 'code-exceptions')
aliasset('exceptions', 'code-exceptions')
tests.add('code-exceptions')


def handle_funcnames(bot, ievent):
示例#21
0
# plugs/underauth.py
#
#

"""Handle non-ident connection on undernet"""

__copyright__ = 'this file is in the public domain'
__author__ = '*****@*****.**'

from gozerbot.callbacks import callbacks
from gozerbot.plughelp import plughelp

plughelp.add('underauth', 'provide callbacks that registers the bot with the \
undernet network')

def pre_underauth_cb(bot, ievent):
    """
    Only respond to the message like:

    NOTICE AUTH :*** Your ident is disabled or broken, to continue
    to connect you must type /QUOTE PASS 16188
    """
    args = ievent.arguments
    try:
        return (args[0] == u'AUTH' and
                args[-3] == u'/QUOTE' and
                args[-2] == u'PASS')
    except Exception, ex:
        return 0

def underauth_cb(bot, ievent):
示例#22
0
# plugs/grab.py

""" quotes grab plugin """

__copyright__ = 'this file is in the public domain'
__depend__ = ['quote', ]

from gozerbot.config import config
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.aliases import aliases
from gozerbot.plughelp import plughelp
from gozerplugs.quote import quotes

plughelp.add('grab', 'grab the last quote of an user')

def handle_quotegrab(bot, ievent):
    """ grab the last last from the given user """
    try:
        from gozerplugs.seen import seen
        assert(seen)
    except (ImportError, AssertionError, NameError):
        ievent.reply("seen plugin not enabled")
        return
    if not quotes:
        ievent.reply('quotes plugin not enabled')
        return
    if not ievent.args:
        ievent.reply('missing <user> argument')
        return
    nick = ievent.args[0].lower()
示例#23
0
""" allow all user in a channel to have permissions. permission that use 
userstate information can not be used, for that the users must be meeted to 
the bot.
"""

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.utils.log import rlog
from gozerbot.tests import tests

plughelp.add('chanperm', 'manage channel permissions')

def handle_chanperm(bot, ievent):

    """ show channel permissions. """

    chan = ievent.channel.lower()

    try:
        p = bot.channels[chan]['perms']
    except (KeyError, TypeError):
        ievent.reply("channel %s has no permissions set" % chan)
        return

    if p:
        ievent.reply('permissions of channel %s: ' % chan, p, dot=True)
示例#24
0
    'log-off',
]
__depending__ = ['mail', 'markov']

from gozerbot.generic import rlog, handle_exception, elapsedstring, dmy, \
hourmin, lockdec, strtotime
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.callbacks import callbacks, jcallbacks
from gozerbot.plughelp import plughelp
from gozerbot.monitor import saymonitor, jabbermonitor
from gozerbot.aliases import aliases, aliasdel
from gozerbot.users import users
import glob, re, thread, pickle, os, mmap, time

plughelp.add('log', 'logs related commands')

# check if logs dir exists if not create it
if not os.path.isdir('logs'):
    os.mkdir('logs')

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


class Logs(object):
    """ hold handles to log files (per channel) """
    def __init__(self, logdir):
        self.logdir = logdir
        self.maps = {}
        self.files = {}
示例#25
0
#
#

__copyright__ = 'this file is in the public domain'

from gozerbot.generic import geturl, striphtml, splittxt, handle_exception, \
fromenc
from gozerbot.commands import cmnds
from gozerbot.aliases import aliases
from gozerbot.examples import examples
from gozerbot.utils.rsslist import rsslist
from gozerbot.plughelp import plughelp
from urllib import quote
import re

plughelp.add('wowwiki', 'query wowwiki')

wikire = re.compile('start content(.*?)end content', re.M)

def getwikidata(url, ievent):
    """ fetch wiki data """
    try:
        result = fromenc(geturl(url))
    except IOError, ex:
        try:
            errno = ex[0]
        except IndexError:
            handle_exception(ievent=ievent)
            return
        ievent.reply('invalid option')
        return
示例#26
0
#
#
#
""" eight ball """

__copyright__ = 'this file is in the public domain'
__revision__ = '$Id: m8b.py 1120 2006-12-30 12:00:00Z deck $'

from gozerbot.generic import handle_exception
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests
import re, random

plughelp.add('8b', 'Ask the magic 8 ball')

balltxt = [
    "Signs point to yes.", "Yes.", "Most likely.", "Without a doubt.",
    "Yes - definitely.", "As I see it, yes.", "You may rely on it.",
    "Outlook good.", "It is certain.", "It is decidedly so.",
    "Reply hazy, try again.", "Better not tell you now.", "Ask again later.",
    "Concentrate and ask again.", "Cannot predict now.", "My sources say no.",
    "Very doubtful.", "My reply is no.", "Outlook not so good.",
    "Don't count on it."
]


def handle_8b(bot, ievent):
    ievent.reply(random.choice(balltxt))
示例#27
0
# gozerplugs/lart.py
#
#

from gozerbot.commands import cmnds
from gozerbot.persist.persistconfig import PersistConfig
from gozerbot.aliases import aliasset
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
import random

plughelp.add("lart", "do the lart")

cfg = PersistConfig()
cfg.define("lartlist", [])


def handle_lart(bot, ievent):
    try:
        who = ievent.args[0]
    except IndexError:
        ievent.missing("<who>")
        return
    try:
        txt = random.choice(cfg.get("lartlist"))
    except IndexError:
        ievent.reply('lart list is empty .. use lart-add to add entries .. use "<who>" as a nick holder')
        return
    txt = txt.replace("<who>", who)
    bot.action(ievent.channel, txt)
示例#28
0
#
#

""" do voice on join """

__copyright__ = "this file is in the public domain"

from gozerbot.commands import cmnds
from gozerbot.callbacks import callbacks
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

plughelp.add(
    "autovoice",
    "enable auto voicing of people join .. commands \
work for the channels the commands are given in",
)


def preautovoice(bot, ievent):
    """ precondition on auto-op .. we must be op """
    if ievent.channel in bot.state["opchan"]:
        return 1


def cbautovoice(bot, ievent):
    """ autovoice callback """
    chandata = 0
    try:
        chandata = bot.channels[ievent.channel]["autovoice"]
示例#29
0
__author__ = 'Landon Fowles'

from gozerbot.generic import geturl, waitforuser, getwho, rlog
from gozerbot.commands import cmnds
from gozerbot.datadir import datadir
from gozerbot.persist.persist import Persist
from gozerbot.users import users
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
from gozerbot.persist.persiststate import UserState
from gozerbot.aliases import aliasset
import time
from xml.dom import minidom
from urllib import urlencode

plughelp.add('weather', 'show weather by zipcode/city name')

def handle_weather(bot, ievent):
    """ show weather using Google's weather API """
    userhost = ""
    loc = ""
    try:
        nick = ievent.options['--u']
        if nick:
            userhost = getwho(bot, nick)
            if not userhost:
                ievent.reply("can't determine username for %s" % nick)
                return
            else:
                try:
                    name = users.getname(userhost)
示例#30
0
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
import os, string, random

plughelp.add('dope', 'for all the junkies out there')

joint = '''
purple haze
white widow
silver haze
mango haze
krystal
mossad
mexican haze
northern lights
master kush
california orange bud
b-52
binnenkweek mix
skunk
jamaican
jack herrer
tafrolt
pakistaan
primero
red libanon
hija
super hija
afghaan
zwarte afghaan
示例#31
0
# plugs/googletalk.py
#
#

""" enable the bot to log into google chat. """ 

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.callbacks import jcallbacks
from gozerbot.generic import rlog
from gozerbot.config import config
from gozerbot.plughelp import plughelp

plughelp.add('googletalk', 'the google talk plugin make it possible to link \
to the googletalk servers .. google changes the JID of the bot so this \
plugin detects this and sets the bots JID .. for this to work the bot must \
be in a googletalk users buddieslist')

def googletalktest(bot, msg):

    """ check if presence callbacks should fire. """

    if not 'google' in bot.host:
        return 0

    if "vcard-temp:x:update" in str(msg):
        newjid = msg.getAttrs()['to']
        if bot.me != str(newjid):
            if bot.me in str(newjid):
                return 1
        
示例#32
0
import time
import re

# Third Party Imports

# Local Imports
from gozerbot.callbacks import callbacks
from gozerbot.commands import cmnds
from gozerbot.datadir import datadir
from gozerbot.persist.pdod import Pdod
from gozerbot.persist.persistconfig import PersistConfig
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
from gozerbot.redispatcher import rebefore

plughelp.add('sed', 'Perform substitution on last message spoken')

cfg = PersistConfig()
cfg.define('cmd_req', 0)
sed_expression = r'^s([/|#.:;])(.*?)\1(.*?)\1?([gi]*)$'
sedre = re.compile(sed_expression)


class LastLine(Pdod):
    def __init__(self):
        self.datadir = os.path.join(datadir, 'plugs', 'sed')
        Pdod.__init__(self, os.path.join(self.datadir, 'sed.data'))
        if not self.data:
            self.data = {}

    def handle_sed(self, bot, ievent):
示例#33
0
from gozerbot.generic import getwho, rlog
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.aliases import aliases
from gozerbot.callbacks import callbacks
from gozerbot.plughelp import plughelp
import Queue
import time

plughelp.add('kickban', 'channel ban list management')

bans = {}
cachetime = 300
timeout = 10


def handle_367(bot, ievent):
    rlog(10, '367', str(ievent))
    channel = ievent.arguments[1].lower()
    if not bot.name in bans or not channel in bans[bot.name]:
        return  # not requested by this plugin
    bans[bot.name][channel].append(ievent.txt.split()[0])


def handle_mode(bot, ievent):
    rlog(10, 'mode', str(ievent))
    # [18 Jan 2008 13:41:29] (mode) cmnd=MODE [email protected] postfix=#eth0-test +b *!*@je.moeder.ook arguments=[u'#eth0-test', u'+b', u'*!*@je.moeder.ook'] nick=maze user=wijnand [email protected] channel=#eth0-test txt= command= args=[] rest= speed=5 options={}


def get_bans(bot, channel):
    # :ironforge.sorcery.net 367 basla #eth0 *!*@71174af5.e1d1a3cf.net.hmsk [email protected] 1200657224
示例#34
0
# plugs/mailexceptions.py
#
#

""" mail exceptions in backlog """

__copyright__ = 'this file is in the public domain'

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.generic import exceptionlist
from gozerbot.plughelp import plughelp
import smtplib

plughelp.add('mailexceptions', 'mail list of occured exceptions to \
[email protected]')

def handle_mailexceptions(bot, ievent):
    """ mailexceptions [<email>] .. mail exceptions in log """
    if not len(exceptionlist):
        ievent.reply("no exceptions available")
        return   
    try:
        mailto = ievent.args[0]
    except IndexError:
        mailto = '*****@*****.**'
    try:
        mailserver = mailto.split('@')[1]
    except IndexError:
        ievent.reply("can't determine mailserver from %s" % mailto)
        return
示例#35
0
# plugs/echo.py
#
#
""" simple echo command """

__copyright__ = 'this file is in the public domain'

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp

plughelp.add('echo', 'simply write back what you tell it')


def handle_echo(bot, ievent):
    """ say back what is being said """
    ievent.reply(ievent.rest)


cmnds.add('echo', handle_echo, 'USER')
examples.add('echo', "echo Hello World!", 'echo')
示例#36
0
__copyright__ = 'this file is in the public domain'

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.users import users
from gozerbot.redispatcher import rebefore, reafter
from gozerbot.aliases import aliases
from gozerbot.callbacks import callbacks
from gozerbot.plugins import plugins
from gozerbot.fleet import fleet
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

plughelp.add(
    'size', 'the size command shows the sizes of plugins that \
provide a size() plugin command and the sizes of some basic structures')


def handle_size(bot, ievent):
    """ size .. show size of core datastructures """
    txtlist = []
    txtlist.append("fleet: %s" % fleet.size())
    txtlist.append("users: %s" % users.size())
    txtlist.append("cmnds: %s" % cmnds.size())
    txtlist.append("callbacks: %s" % callbacks.size())
    txtlist.append("rebefore: %s" % rebefore.size())
    txtlist.append("reafter: %s" % reafter.size())
    txtlist.append("aliases: %s" % len(aliases.data))
    txtlist.append("examples: %s" % examples.size())
    plugsizes = plugins.plugsizes()
示例#37
0
# plugs/tell.py
#
#

""" send the output of a command to <nick>. """

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plugins import plugins
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

plughelp.add('tell', 'the tell command sends the output of a command to \
another user')

def handle_tell(bot, ievent):
    """ send output of command to another user """
    if ievent.msg:
        ievent.reply('tell can only be used in a channel')
        return 
    try:
        nick, cmnd = ievent.rest.split(' ', 1)
    except ValueError:
        ievent.missing('<nick> <command>')
        return
    ievent.txt = cmnd
    #if not plugins.woulddispatch(bot, ievent):
    #    ievent.reply("can't execute %s" % cmnd)
    #    return  
    result = plugins.cmnd(bot, ievent)
    if not result:
示例#38
0
#
#

__copyright__ = 'this file is in the public domain'

from gozerbot.generic import geturl, striphtml, splittxt, handle_exception, \
fromenc
from gozerbot.commands import cmnds
from gozerbot.aliases import aliases
from gozerbot.examples import examples
from gozerbot.utils.rsslist import rsslist
from gozerbot.plughelp import plughelp
from urllib import quote
import re

plughelp.add('wikipedia', 'query wikipedia')

wikire = re.compile('start content(.*?)end content', re.M)

def searchwiki(txt, lang='en'):
    for i in txt.split():
        if i.startswith('-'):
            if len(i) != 3:
                continue
            else:
                lang = i[1:]
            continue
    txt = txt.replace("-%s" % lang, '')
    txt = txt.strip().capitalize()
    what = txt.strip().replace(' ', '_')
    url = 'http://%s.wikipedia.org/wiki/Special:Export/%s' % (lang, \
示例#39
0
# gozerplugs/beats.py
#
#

""" internet time .beats """

__copyright__ = 'this file is in the public domain'

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests
import time, math

plughelp.add('beats', 'show internet time')

def handle_beats(bot, ievent):
    """ beats .. show current internet time """
    beats = ((time.time() + 3600) % 86400) / 86.4
    beats = int(math.floor(beats))
    ievent.reply('@' + str(beats))

cmnds.add('beats', handle_beats, 'USER')
examples.add('beats', 'show current internet time', 'beats')
tests.add('beats' , '@')
示例#40
0
#
#

__copyright__ = 'this file is in the public domain'

from gozerbot.generic import elapsedstring, getwho, jsonstring
from gozerbot.commands import cmnds
from gozerbot.callbacks import callbacks, jcallbacks
from gozerbot.examples import examples
from gozerbot.datadir import datadir
from gozerbot.persist.persist import PlugPersist
from gozerbot.plughelp import plughelp
from gozerbot.aliases import aliases
import time, os

plughelp.add('idle', 'show how long a user or channel has been idle')

idle = PlugPersist('idle.data')
if not idle.data:
    idle.data = {}


def shutdown():
    idle.save()


def preidle(bot, ievent):
    """ idle precondition aka check if it is not a command """
    if ievent.usercmnd:
        return 0
    else:
示例#41
0
# gozerplugs/buzz.py
#
#

__author__ = 'unknown'

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp

plughelp.add('buzz', 'create a buzz word')

from random import randint

verb = [
    "implement", "utilize", "integrate", "streamline", "optimize", "evolve",
    "transform", "embrace", "enable", "orchestrate", "leverage", "reinvent",
    "aggregate", "architect", "enhance", "incentivize", "morph", "empower",
    "envisioneer", "monetize", "harness", "facilitate", "seize",
    "disintermediate", "synergize", "strategize", "deploy", "brand", "grow",
    "brand", "grow", "target", "syndicate", "synthesize", "deliver", "mesh",
    "incubate", "engage", "maximize", "benchmark", "expedite",
    "reintermediate", "expedite", "reintermediate", "whiteboard", "visualize",
    "repurpose", "innovate", "scale", "unleash", "drive", "extend", "engineer",
    "revolutionize", "generate", "exploit", "transition", "e-enable",
    "iterate", "cultivate", "matrix", "productize", "redefine",
    "recontextualize"
]

adj = [
    "clicks-and-mortar", "value-added", "vertical", "proactive", "robust",
示例#42
0
import time
import re

# Third Party Imports

# Local Imports
from gozerbot.callbacks import callbacks
from gozerbot.commands import cmnds
from gozerbot.datadir import datadir
from gozerbot.persist.pdod import Pdod
from gozerbot.persist.persistconfig import PersistConfig
from gozerbot.plughelp import plughelp
from gozerbot.examples import examples
from gozerbot.redispatcher import rebefore

plughelp.add('sed', 'Perform substitution on last message spoken')

cfg = PersistConfig()
cfg.define('cmd_req', 0)
sed_expression = r'^s([/|#.:;])(.*?)\1(.*?)\1?([gi]*)$'
sedre = re.compile(sed_expression)

class LastLine(Pdod):
    def __init__(self):
        self.datadir = os.path.join(datadir, 'plugs', 'sed')
        Pdod.__init__(self, os.path.join(self.datadir, 'sed.data'))
        if not self.data:
            self.data = {}

    def handle_sed(self, bot, ievent):
        """ Perform substitution """
示例#43
0
""" do the timebomb dance. """

__copyright__ = 'BSD'
__author__ = 'clone at magtar.org'

from gozerbot.generic import getwho
from gozerbot.commands import cmnds
from gozerbot.plughelp import plughelp
from gozerbot.persist.persist import PlugPersist
from gozerbot.aliases import aliasset

from time import sleep, time
from random import randint, shuffle

plughelp.add('timebomb', 'blow your buddies to smithereens !timebomb <victim>')
plughelp.add('cut', 'try to defuse a bomb placed with !timebomb by cutting a wire i.e. !cut blue')

# define plugpersist outside localscope, you only want to initiate it once.
bomb = PlugPersist('bomb')
bomb.data = []

def timebomb(bot, ievent):
    # check if we have ops
    if ievent.channel not in bot.state['opchan']:
        bot.action(ievent.channel, "bends over and farts in %s's general direction." % ievent.nick)
        return
    # check if we are already running a bomb
    if bomb.data:
        bot.action(ievent.channel ,"points at the bulge in %s's pants." % bomb.data[0])
        return
示例#44
0
文件: asn.py 项目: jskoetsier/asn
import json
import requests
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests

# add help

plughelp.add('asn', 'lookup ASN via peeringdb')

def handle_asn(bot, ievent):
    asnumber_in = ""
    try: what = ievent.args[0]
    except IndexError: ievent.missing("<asn>"); return
    try:
         asnumber_in = what
         url = "https://stat.ripe.net/data/as-overview/data.json?resource=" + asnumber_in
         resp = requests.get(url=url)
         pdb_json = json.loads(resp.text)
         network_name = pdb_json['data'][0]['holder']
         resultstring = "AS Number: %s has name: %s" % (asnumber_in, network_name)
         ievent.reply(resultstring)
    except Exception, ex: ievent.reply("Invalid ASN") ; return


cmnds.add('asn', handle_asn, 'USER')
examples.add('asn', 'Lookup as number on ripestat', 'asn 8315')
tests.add('asn 8315')

### In elkaar gerost door phreak ergens in 2020.
示例#45
0
# Idea not so loosely based on [email protected]'s eggdrop timebomb
""" do the timebomb dance. """

__copyright__ = 'BSD'
__author__ = 'clone at magtar.org'

from gozerbot.generic import getwho
from gozerbot.commands import cmnds
from gozerbot.plughelp import plughelp
from gozerbot.persist.persist import PlugPersist
from gozerbot.aliases import aliasset

from time import sleep, time
from random import randint, shuffle

plughelp.add('timebomb', 'blow your buddies to smithereens !timebomb <victim>')
plughelp.add(
    'cut',
    'try to defuse a bomb placed with !timebomb by cutting a wire i.e. !cut blue'
)

# define plugpersist outside localscope, you only want to initiate it once.
bomb = PlugPersist('bomb')
bomb.data = []


def timebomb(bot, ievent):
    # check if we have ops
    if ievent.channel not in bot.state['opchan']:
        bot.action(
            ievent.channel,
示例#46
0
__copyright__ = 'this file is in the public domain'

from gozerbot.generic import rlog
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.callbacks import callbacks
from gozerbot.users import users
from gozerbot.plugins import plugins
from gozerbot.datadir import datadir
from gozerbot.persist.persist import PlugPersist
from gozerbot.plughelp import plughelp
from gozerbot.tests import tests
import time, os

plughelp.add('away', "keep notice of who's away")

lasttime = []

# use datadir/away as pickle file
awaydict = PlugPersist('away.data')

# see if data attribute is set otherwise init it
if not awaydict.data:
    awaydict.data = {}
if not awaydict.data.has_key('enable'):
    awaydict.data['enable'] = 0
    awaydict.save()

def init():
    """ init plugin """
示例#47
0
            for item, descrlist in oldinfo.data.iteritems():
                for descr in descrlist:
                    info.add(item, descr, 'none', 0)
                    teller += 1
        except IOError, ex:
            if "No such file" in str(ex):
                rlog(10, 'infoitem', 'nothing to upgrade')
        except Exception, ex:
            rlog(10, 'infoitem', "can't upgrade: %s" % str(ex))
            return
    rlog(10, 'infoitem', 'upgraded %s infoitems' % str(teller))
    return teller

import thread, os, time

plughelp.add('infoitem', 'also known as factoids .. info can be retrieved \
by keyword or searched')

infolock = thread.allocate_lock()

# create lock descriptor
locked = lockdec(infolock)

class InfoitemsDb(object):

    """ information items """

    @trans 
    def add(self, session, item, description, userhost, ttime):
        """ add an item """
        item = item.lower()
        result = 0
示例#48
0
"""

__copyright__ = 'this file is in the public domain'
__gendocfirst__ = ['pt-add', ]
__gendoclast__ = ['pt-del', ]

from gozerbot.utils.generic import convertpickle
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.users import users
from gozerbot.datadir import datadir
from gozerbot.persist.persist import PlugPersist
from gozerbot.plughelp import plughelp

plughelp.add('projecttracker', 'track hours spent working on projects')

## UPGRADE PART

def upgrade():
    convertpickle(datadir + os.sep + 'old' + os.sep + 'pt-projects', \
datadir + os.sep + 'plugs' + os.sep + 'projecttracker' + os.sep + 'pt-projects')
    convertpickle(datadir + os.sep + 'old' + os.sep + 'pt-contrib', \
datadir + os.sep + 'plugs' + os.sep + 'projecttracker' + os.sep + 'pt-contrib')

## END UPGRADE PART

import os

projects = PlugPersist('pt-projects')
contrib  = PlugPersist('pt-contrib') 
示例#49
0
# plugs/drinks.py
#
#

from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.plughelp import plughelp
import os, string, random

plughelp.add('drinks', 'serve coffee/tea or beer')

coffee = []
tea = []
beer = []

def init():
    global coffee
    global tea
    global beer
    for i in  coffeetxt.split('\n'):
        if i:
            coffee.append(i.strip())
    for i in teatxt.split('\n'):
        if i:
            tea.append(i.strip())
    for i in beertxt.split('\n'):
        if i:
            beer.append(i.strip())
    return 1

def handle_coffee(bot, ievent):
示例#50
0
#
# I included the Twitter API, because I had to fix some minor issues. These
# issues have been reported so maybe the API part will be removed from this
# plugin at a later stadium.

import os
from gozerbot.commands import cmnds
from gozerbot.datadir import datadir
from gozerbot.examples import examples
from gozerbot.persist.pdol import Pdol
from gozerbot.plughelp import plughelp
from gozerbot.utils.textutils import html_unescape
from gozerbot.utils.generic import waitforqueue
from gozerbot.plughelp import plughelp

plughelp.add('twitter', 'do the twitter')

__version__ = '0.2'

#
# twitter-py stuff
#
# Twitter API
# (c) DeWitt Clinton <*****@*****.**>
# Apache License 2.0

import base64
import md5
import os
import sys
import tempfile
示例#51
0
from gozerbot.examples import examples
from gozerbot.generic import geturl, posturl, waitforqueue
from gozerbot.plughelp import plughelp
# compatibility check (since r1701)
try:
    from gozerbot.textutils import html_unescape
except ImportError:
    import htmllib

    def html_unescape(s):
        p = htmllib.HTMLParser(None)
        p.save_bgn()
        p.feed(s)
        return p.save_end()

plughelp.add('translate', 'translate between languages')

class TranslateLanguageException(Exception):
    pass

class TranslateLoginException(Exception):
    pass

class Translate:
    
    lang = ['English/Spanish', 'English/French', 'English/German', 'English/Italian', 'English/Dutch', 'English/Portuguese', 'English/Russian', 'English/Norwegian', 'English/SimplifiedChinese', 'English/TraditionalChinese', 'English/Japanese', 'Spanish/English', 'French/English', 'German/English', 'Italian/English', 'Dutch/English', 'Portuguese/English', 'Russian/English', 'Japanese/English']
    re_username = re.compile('<input type="hidden" name="username" value="([^"]+)" />', re.I | re.M)
    re_password = re.compile('<input type="hidden" name="password" value="([^"]+)" />', re.I | re.M)
    
    def translate(self, lang_from, lang_to, text):
        # fix case stuff
示例#52
0
from gozerbot.utils.generic import convertpickle, jsonstring
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.callbacks import callbacks, jcallbacks
from gozerbot.fleet import fleet
from gozerbot.monitor import saymonitor, jabbermonitor
from gozerbot.datadir import datadir
from gozerbot.persist.pdol import Pdol
from gozerbot.plughelp import plughelp
from gozerbot.ignore import shouldignore
from gozerbot.generic import rlog
from gozerbot.threads.thr import start_new_thread
import time, os

plughelp.add('relay', 'relay between fleet bots or channels')

## UPGRADE PART

def upgrade():
    convertpickle(datadir + os.sep + 'old' + os.sep + 'relay', \
datadir + os.sep + 'plugs' + os.sep + 'relay' + os.sep + 'relay')

class Relay(Pdol):

    """ relay is implemented as a pickled dict of lists """

    def check(self, botname, channel, txt, fromm=None):
        """ check if we relay on (botname, channel) .. if so do output """
        channel = channel.lower()
        indexstring = jsonstring((botname, channel))