示例#1
0
文件: http.py 项目: glesica/chibot
"""
import requests
from chibot import plugins


MAX_URLS = 10


class HTTPStatusPlugin(plugins.Plugin):
    _name = 'httpstatus'
    _arguments = (
        ('urls', ('tok',), None),
    )
    _response_class = plugins.NoticeResponse

    def run(self, urls, **kwargs):
        if not urls:
            return 'Provide one or more URLS'

        resp = []
        if len(urls) > MAX_URLS:
            resp.append('Processing first %s URLS' % MAX_URLS)

        for u in urls[:MAX_URLS]:
            code = requests.get(u).status_code
            resp.append('%s ... %s' % (u, code))

        return resp

plugins.register(HTTPStatusPlugin())
示例#2
0
文件: links.py 项目: glesica/chibot
            meta = connection.chibot.links_meta.find_and_modify({}, {"$inc": {"counter": 1}}, new=True)
            link = connection.chibot.Link()
            link["id"] = int(meta["counter"])
            link["timestamp"] = datetime.datetime.now()
            link["nickname"] = message.nickname
            link["username"] = message.user
            link["host"] = message.host
            link["url"] = u
            link.save()

            resp.append("%s: %s" % (link["id"], link["url"]))

        return resp


plugins.register(URLIndexPlugin())


class URLTitlePlugin(plugins.Plugin):
    _name = "urltitle"
    _arguments = (("url_id", int, None), ("title", str, None))
    _response_class = plugins.NoticeResponse

    def run(self, url_id, title, **kwargs):
        resp = []
        resp.append("%s" % url_id)
        resp.append(title)


plugins.register(URLTitlePlugin())
示例#3
0
文件: logs.py 项目: glesica/chibot
    _name = None

    def _message_filter(self, message):
        return message.public

    def run(self, message):
        entry = connection.chibot.log.LogEntry()
        entry['nickname'] = message.nickname
        entry['username'] = message.user
        entry['host'] = message.host
        entry['message'] = message.content
        entry['timestamp'] = datetime.datetime.now()
        entry.save()
        return None

plugins.register(LogEntryPlugin())


class NickStatsPlugin(plugins.Plugin):
    _name = 'nickstats'
    _arguments = (
        ('nick', 'tok', None),
    )
    _response_class = plugins.NoticeResponse

    def run(self, nick, **kwargs):
        resp = []

        resp.append('Nickname: %s' % nick)

        # Hit the DB