How to use the errbot.BotPlugin function in errbot

To help you get started, we’ve selected a few errbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github errbotio / errbot / tests / dependent_plugins / double.py View on Github external
from errbot import BotPlugin


class Double(BotPlugin):
    pass
github cylance / CyBot / plugins / secnews / secnews.py View on Github external
# !secnews is used for qurying Google News for CyberSecurity

import requests, re
import xml.etree.ElementTree as ET
from errbot import BotPlugin, botcmd, arg_botcmd

class secnews(BotPlugin):

    @botcmd(split_args_with=None, hidden=True)
    def secnews(self, msg, args):

        #Define default number of articles
        limit=10
        urlip = "https://news.google.com/news/rss/search/section/q/cybersecurity/cybersecurity?hl=en&gl=US&ned=us"

        print(len(args))
        if len(args)!=1 and len(args)!=0:
            return("Incorrect number of parameters.  Can either be 0 or 1 arguments.")
            exit()

        if len(args)==1:
            if args[0].isdigit():
                limit=int(args[0])
github coala / corobo / plugins / ship_it.py View on Github external
import random
import re

from errbot import BotPlugin, re_botcmd


class Ship_it(BotPlugin):
    """
    Show motivational ship it squirrel images.
    """

    # start ignoring LineLengthBear PyCodeStyleBear
    IMAGES = [
        'http://i.imgur.com/DPVM1.png',
        'http://d2f8dzk2mhcqts.cloudfront.net/0772_PEW_Roundup/09_Squirrel.jpg',
        'http://www.cybersalt.org/images/funnypictures/s/supersquirrel.jpg',
        'http://www.zmescience.com/wp-content/uploads/2010/09/squirrel.jpg',
    ]
    # stop ignoring LineLengthBear PyCodeStyleBear

    @re_botcmd(pattern=r'ship\s*it',
               re_cmd_name_help='ship it',
               flags=re.IGNORECASE)
github coala / corobo / plugins / pitchfork.py View on Github external
import re
import string
import textwrap

from errbot import BotPlugin, botcmd


class Pitchfork(BotPlugin):
    """
    To pitchfork users down to ...
    """

    @botcmd
    def pitchfork(self, msg, arg):
        """
        To pitchfork user down to ...
        """
        match = re.match(r'@?([\w-]+)(?:\s+(?:down\s+)?to\s+(.+))?$',
                         arg)
        if match:
            user = match.group(1)
            place = match.group(2) if match.group(2) else 'offtopic'
            return textwrap.dedent((
                string.Template(r"""
github coala / corobo / plugins / labhub.py View on Github external
import datetime
import re
import time

import github3
from IGitt.GitHub.GitHub import GitHub, GitHubToken
from IGitt.GitLab.GitLab import GitLab, GitLabPrivateToken
from errbot import BotPlugin, cmdfilter, re_botcmd
from errbot.templating import tenv

from plugins import constants
from utils.backends import message_link
from utils.mixin import DefaultConfigMixin


class LabHub(DefaultConfigMixin, BotPlugin):
    """GitHub and GitLab utilities"""  # Ignore QuotesBear

    CONFIG_TEMPLATE = {
        'GH_ORG_NAME': None,
        'GH_TOKEN': None,
        'GL_ORG_NAME': None,
        'GL_TOKEN': None,
    }

    def activate(self):
        super().activate()

        teams = dict()
        try:
            gh = github3.login(token=self.config['GH_TOKEN'])
            assert gh is not None
github errbotio / err-code / code.py View on Github external
'run': str(run),
            'submit': 'Submit'}
    r = requests.post('http://codepad.org/', data=data)
    if not r.ok:
        return "Failed to contact codepad: %s" % r.content

    soup = BeautifulSoup(r.content, 'lxml')
    output = soup.find('a', attrs={'name': 'output'})
    if not output:
        return "Failed to parse the result page."

    result = output.findNext('div').table.tr.td.findNext('td').div.pre.text
    return '```\n%s\n```' % result.strip('\n ')


class CodeBot(BotPlugin):

    @botcmd
    def python(self, _, args):
        """ Execute the python expression.
            ie. !python print(range(10))
        """
        return scrape_codepad(args)

    @botcmd
    def c(self, _, args):
        """ Execute the c expression """
        return scrape_codepad(args, lang='C')

    @botcmd
    def cpp(self, _, args):
        """ Execute the cpp expression """
github errbotio / errbot / errbot / core_plugins / utils.py View on Github external
from os import path

from errbot import BotPlugin, botcmd


def tail(f, window=20):
    return ''.join(f.readlines()[-window:])


class Utils(BotPlugin):

    # noinspection PyUnusedLocal
    @botcmd
    def echo(self, _, args):
        """ A simple echo command. Useful for encoding tests etc ...
        """
        return args

    @botcmd
    def whoami(self, msg, args):
        """ A simple command echoing the details of your identifier. Useful to debug identity problems.
        """
        if args:
            frm = self.build_identifier(str(args).strip('"'))
        else:
            frm = msg.frm
github coala / corobo / plugins / deprecate_bot_prefixes.py View on Github external
from errbot import BotPlugin


class DeprecateBotPrefixes(BotPlugin):
    """
    A callback for every message that starts with depecrated prefix, hence,
    leaving a deprecation notice
    """

    def callback_message(self, msg):
        """
        Notify the user issuing the command that use deprecated prefix.
        """

        for deprecated_prefix in self.bot_config.BOT_DEPRECATED_PREFIXES:
            if msg.body.startswith(deprecated_prefix):
                self.send(
                    msg.frm,
                    "@{} usage of {} has been deprecated, please use {} "
                    "from now on.".format(msg.frm.nick, deprecated_prefix,
github coala / corobo / plugins / spam.py View on Github external
from errbot import BotPlugin
from errbot.templating import tenv

from plugins import constants
from utils.mixin import DefaultConfigMixin


class SpammingAlert(DefaultConfigMixin, BotPlugin):
    """
    A plugin which alerts the user that they might be spamming.
    """

    CONFIG_TEMPLATE = {
        'MAX_MSG_LEN': constants.MAX_MSG_LEN,
        'MAX_LINES': constants.MAX_LINES
    }

    def check_configuration(self, configuration):
        pass

    def callback_message(self, msg):
        """
        Alert the user that his/her message is too long or has too
        many lines.
github cylance / CyBot / plugins / geoip / geoip.py View on Github external
# !geoip is used for Querying the freegeoip.net API

import os, requests, json, re
from errbot import BotPlugin, botcmd, arg_botcmd

class geoip(BotPlugin):

    @arg_botcmd('query', type=str)  # flags a command
    def geoip(self, msg, query=None):
        #Process defanged FQDN
        query = re.sub('[\[()\]]', '', query)
        headers = {
            "Accept-Encoding": "gzip, deflate",
            "User-Agent" : "You all rock!"
            }
        response = requests.get('http://ip-api.com/json/' + query,
            headers=headers)

        json_resp = response.json()
#        print(json_resp)
        if json_resp["status"] == "success":
            answer = "Status: " + json_resp["status"] + "\r\n"