def __init__(self): Plugin.__init__(self, 'sympathy') self._set_summary(_('Calculates P1tr\'s sympathy towards a user')) self._add_command( 'sympathy', '[<nick>]', _('Shows sympathy statistics \ towards the indicated nick (or towards you, if no nick is indicated).')) self._add_command('snack', None, _('Gives your bot a well deserved \ snack.')) self._add_command('dispraise', None, _('Use only if bot was bad to \ you.')) self._add_command('hi', None, _('Greet P1tr.')) self.mind = self._load_resource('mind') # Structure of self.mind dictionary: # {'server': { # 'nick': { # 'calls': {'callers_nick': float, }, # 'sympathy': float, # 'actions': int, }, # '_known_channels: [], # '_vips': [], }, # } self.badwords = (_('sucker'), _('asshole'), _('idiot'), _('scum'))
def __init__(self): Plugin.__init__(self, 'unix') self._set_summary(_('Plugin to access some popular UNIX applications')) self._add_command( 'fortune', '[<type>]', _('displays a random \ fortune. See "help fortune types".')) self._add_command( 'ddate', None, _('displays the current date in the \ the discordian calendar.')) self._add_help_topic( 'fortune_types', _('Available fortune types: \ fortunes, literature, riddles; default: all.')) self.wtf_path = '/usr/share/games/bsdgames/' self.wtf_parseable = True wtf_enabled = True if not os.path.isfile(os.path.join(self.wtf_path, 'acronyms')): self.wtf_parseable = False if self._get_output('wtf', False, False): log('i', 'Falling back to system\'s wtf.') else: wtf_enabled = False log('w', 'Couldn\'t find wtf installation; command disabled.') if wtf_enabled: self._add_command('wtf', '<acronym> [<type>]', 'tells you what \ <acronym> means.')
def __init__(self): Plugin.__init__(self, 'insult') self._set_summary(_('Plugin to insult somebody in the channel')) self._add_command('insult', '<nick>', _('Insults nick.')) self._add_command('add_insult', '<phrase>', _('Adds phrase to the \ insults file.')) self._add_command('delete_insult', '<phrase>', _('Deletes phrase \ from the insults file.')) self.insults = self._load_resource('insults') if not self.insults: import urllib2 log('w', 'No insults found in your insults file. Fetching them...') self.insults['ins'] = [] try: insults = urllib2.urlopen('http://server.austriangeekforce.' + \ 'net/insults.txt') insult = True while insult: insult = insults.readline()[:-1] if insult: self._add(insult) except urllib2.URLError: log('e', 'Could not fetch insults.') self._add('You are dumber than someone who knows just one ' + \ 'insult!') raise
def __init__(self): Plugin.__init__(self, 'unix') self._set_summary(_('Plugin to access some popular UNIX applications')) self._add_command('fortune', '[<type>]', _('displays a random \ fortune. See "help fortune types".')) self._add_command('ddate', None, _('displays the current date in the \ the discordian calendar.')) self._add_help_topic('fortune_types', _('Available fortune types: \ fortunes, literature, riddles; default: all.')) self.wtf_path = '/usr/share/games/bsdgames/' self.wtf_parseable = True wtf_enabled = True if not os.path.isfile(os.path.join(self.wtf_path, 'acronyms')): self.wtf_parseable = False if self._get_output('wtf', False, False): log('i', 'Falling back to system\'s wtf.') else: wtf_enabled = False log('w', 'Couldn\'t find wtf installation; command disabled.') if wtf_enabled: self._add_command('wtf', '<acronym> [<type>]', 'tells you what \ <acronym> means.')
def __init__(self): Plugin.__init__(self, 'basics') self._set_summary(_('Plugin for basic IRC operations')) self._add_command('join', '<channel>', _('makes P1tr join channel')) self._add_command( 'part', '[<channel>]', _('makes P1tr part channel. \ If channel is not given he parts the current one.')) self._add_command('quit', None, _('shuts P1tr down.')) self._add_command( 'mode', '<mode> [<nick|mask>]', _('sets channel \ modes to mode; add nick or mask if required for the particular mode.')) self._add_command( 'opme', None, _('gives you op if P1tr is able to \ and you have the appropriate level')) self._add_command( 'lang', '<code>', _('set P1tr\'s language to code. \ Example: lang ca')) self._add_command('reload', None, _('reloads all plugins.')) self._add_command('restart', None, _('restarts the bot.')) self._add_command('ping', None, 'says pong.') self._add_command('say', '<channel> <message>', _('lets the bot say \ <message> in <channel>')) self._add_command('action', '<channel> <something>', _('lets the bot do \ <something> in <channel>')) self._add_command('nick', '<nickname>', _('changes P1tr\'s nick to \ nickname.'))
def __init__(self): Plugin.__init__(self, "warn") self._set_summary( _( "Enables users with a higher level to warn other \ users in case they behave inappropriately. After being warned for three \ times, P1tr automatically kicks this user if he is op." ) ) self._add_command( "warn", "<nick> <reason>", _( "warns user with the \ given reason." ), ) self._add_command( "criminal_record", "[<nick>]", _( 'if no parameters \ given, this command shows the invoker\'s own "criminal record". Users with \ higher levels can view the criminal records of other users.' ), ) self.record = self._load_resource("criminal_record")
def __init__(self): Plugin.__init__(self, 'tracker') self._set_summary( _('Counts how often a word is mentioned. \ Case-sensitive. Words get counted only in one channel')) self._add_command('track', '<word>', _('Adds word to tracklist.')) self._add_command('untrack', '<word>', _('Removes word from \ tracklist.')) self._add_command( 'tracklist', '<channel>', _('Shows all tracked \ words for channel. If channel is not given, the words of the current one get \ displayed.')) self._add_command( 'trackstats', '<word>', _('Shows how often word \ was mentioned and the three people who mention it the most.')) self.resource = self._load_resource('resource') # Structure of self.resource dictionary: # {'server': {'channel': {'word': {'nick': int, }, }, }, } self.watched = [] # For better performance inside listener all words P1tr watches # anywhere are stored in self.watched. for server in self.resource: for channel in self.resource[server]: self.watched.extend(self.resource[server][channel].keys())
def __init__(self): Plugin.__init__(self, 'launchpad') self._set_summary(_('Plugin that provides some Launchpad related \ features')) self._add_command('lp', '<bug number>', _('displays information about \ the given bug.')) self._add_command('lp_listen', None, _('active/deactivate listening \ for Launchpad bugs.')) if xdata_bool(configuration, self.name, 'exclusive'): bugrule_str = r'\b(?:[bB][uU][gG]|[lL][pP]):?\s+?#?([0-9]+)\b' else: bugrule_str = r'\b(?:[lL][pP]):?\s+(?:[bB][uU][gG]\s+)?#?([0-9]+)\b' self.bugrule = re.compile(bugrule_str) self.bugurlrule = re.compile(r'\bhttps?://(?:bugs.)?(?:edge.)?' +\ r'launchpad.net/[a-zA-Z0-9\-+~/]+/([0-9]+)\b') if xdata_bool(configuration, self.name, 'passive'): self._listen = False else: self._listen = True # Loop protection # Format: {'channel_name': [(timestamp, bugid), (timestamp, bugid)]} self._lastbugs = {}
def __init__(self): Plugin.__init__(self, 'textutils') self._set_summary(_('Plugin to return length and reversed string')) self._add_command('length', '<string>', _('returns the length of the \ given string')) self._add_command('reverse', '<string>', _('reverses the given \ string'))
def __init__(self): Plugin.__init__(self, 'vote') self._set_summary(_('Plugin for votations')) self._add_command('vote', None, _('starts a vote.')) self._add_command('endvote', None, _('ends a running votation.')) self._listen = False self._votings = {}
def __init__(self): Plugin.__init__(self, 'memo') self._set_summary(_('Saves and delivers memos to a given user')) self._add_command('memo', '<recipient> <message>', _('Delivers \ message to recipient as soon as he shows up somewhere I am (join or \ new private message)')) self._add_command('burn_memos', '<recipient>', _('Clear all memos \ from storage. If recipient is given, only memos to him are being \ deleted.')) self.mailbag = self._load_resource('mailbag')
def __init__(self): Plugin.__init__(self, 'karma') self._set_summary(_('Keeps track of the karma people/things have')) self._add_command('karma', '<item>', _('Displays Karma statistics for\ item. If item is not given, it shows global karma stats.')) self._add_command('reset_karma', '<item>', _('Resets karma stats for \ item.')) self._add_help_topic('usage', _('Append ++/-- to a term without \ spaces in it to in-/decrease the karma of this term. Use the karma command \ to get statistics to a certain term.')) self.vault = self._load_resource('vault')
def __init__(self): Plugin.__init__(self, 'search') self._set_summary('Plugin to provide a quick way to generate search \ links') self._add_command('search', '<searchengine> <something>', _('returns a link of the given search engine searching something')) self.searches = {'-google': 'http://www.google.com/search?\ hl=en&q=searchstring', '-wiki_en': 'http://en.wikipedia.org/wiki/Special:Search?search=searchstring', '-wiki_de': 'http://de.wikipedia.org/wiki/Special:Search?search=searchstring', '-yahoo': 'http://search.yahoo.com/search?p=searchstring', '-wikia': 'http://re.search.wikia.com/search#searchstring', }
def __init__(self): Plugin.__init__(self, 'auth') self._set_summary(_('Authentification plugin')) self._add_command('auth', '<password>', _('Show that you are you by \ using your password from registration. Better do this using private \ adressing.')) self._add_command('register', '<password>', _('Registers your nick \ with password. Better do this using private adressing.')) self._add_command('set', '<user> <level>', _('Changes user\'s level \ to the indicated one, which can be an integer from 1 to 29.')) self._add_command('level', '[<user>]', _('Shows user\'s level, or \ yours if you specify no username.')) for user in User.users.values(): user.trusted = False
def __init__(self): Plugin.__init__(self, 'dice') self._set_summary(_('Plugin for rolling various dices')) self._add_command('roll', '<expression>', _('makes P1tr roll one or \ more dices like specified in expression. expression should look like this: \ d6 or 2d20 or d3+7; d and the succeeding number are obligate and specify the \ dice type. The preceeding number specifies the number of rolls. You can \ append a small mathematical expression with one of the symbols +-*/. The \ results of multiple expressions get added. Limits: see "help dice limits"')) self._add_help_topic('limits', _('The number of rolls and the \ modification must not have more than 2 digits, number of sides is limited \ to three.')) self._add_command('dice', '<expression>', _('alias of roll. See \ "help dice roll" for help'))
def __init__(self): Plugin.__init__(self, 'memo') self._set_summary(_('Saves and delivers memos to a given user')) self._add_command( 'memo', '<recipient> <message>', _('Delivers \ message to recipient as soon as he shows up somewhere I am (join or \ new private message)')) self._add_command( 'burn_memos', '<recipient>', _('Clear all memos \ from storage. If recipient is given, only memos to him are being \ deleted.')) self.mailbag = self._load_resource('mailbag')
def __init__(self): Plugin.__init__(self, 'warn') self._set_summary( _('Enables users with a higher level to warn other \ users in case they behave inappropriately. After being warned for three \ times, P1tr automatically kicks this user if he is op.')) self._add_command('warn', '<nick> <reason>', _('warns user with the \ given reason.')) self._add_command( 'criminal_record', '[<nick>]', _('if no parameters \ given, this command shows the invoker\'s own "criminal record". Users with \ higher levels can view the criminal records of other users.')) self.record = self._load_resource('criminal_record')
def __init__(self): Plugin.__init__(self, 'karma') self._set_summary(_('Keeps track of the karma people/things have')) self._add_command( 'karma', '<item>', _('Displays Karma statistics for\ item. If item is not given, it shows global karma stats.')) self._add_command('reset_karma', '<item>', _('Resets karma stats for \ item.')) self._add_help_topic( 'usage', _('Append ++/-- to a term without \ spaces in it to in-/decrease the karma of this term. Use the karma command \ to get statistics to a certain term.')) self.vault = self._load_resource('vault')
def __init__(self): Plugin.__init__(self, 'search') self._set_summary('Plugin to provide a quick way to generate search \ links') self._add_command( 'search', '<searchengine> <something>', _('returns a link of the given search engine searching something')) self.searches = { '-google': 'http://www.google.com/search?\ hl=en&q=searchstring', '-wiki_en': 'http://en.wikipedia.org/wiki/Special:Search?search=searchstring', '-wiki_de': 'http://de.wikipedia.org/wiki/Special:Search?search=searchstring', '-yahoo': 'http://search.yahoo.com/search?p=searchstring', '-wikia': 'http://re.search.wikia.com/search#searchstring', }
def test_apply_cutting_overlap(self): """Test Plugin.apply_cutting_overlap()!""" overlap = 20 plugin = Plugin() g = Graphic("arrow.svg") g.set_scale(HPGL.HPGL_SCALE,HPGL.HPGL_SCALE) paths = g.get_polyline() lengths = [] for path in paths: lengths.append(g.get_path_length(path=path)) plugin.apply_cutting_overlap(paths,overlap) for path,length in zip(paths,lengths): if path_is_closed(path): new_length = g.get_path_length(path=path) assert round(length+overlap,10) == round(new_length,10), "%s != %s" % (round(length+overlap,10),round(new_length,10)) else: assert round(length,10) == round(new_length,10), "%s != %s" % (round(length,10),round(new_length,10))
def __init__(self): Plugin.__init__(self, 'factoids') self._set_summary(_('Factoids stores strings to a keyword')) self._add_command('factoids', '[<filter>]', _('shows a list of \ keywords')) self._add_command( 'associate', '<word> <info>', _('Associates the \ given info string with the word.')) self._add_command( 'forget', '<word> <id>', _('If id is given it makes \ me delete the word\'s fact with that id, otherwise I forget everything about \ word.')) self._add_command('random_fact', None, _('displays a random fact from \ any word')) self._add_command( 'search_factoid', '<term>', _('searches all \ factoids for term. Add "word:something" in the begining to find only factoids \ of something')) self._add_help_topic( 'association', _('Examples: Arthur is the king \ of the Britons; Romans are hook-nosed.')) self._add_help_topic( 'remembering', _('Example: arthur? - response: \ [0] Arthur is the king of the britons\\n[1] Arthur is seeking the holy grail.') ) self.vault = self._load_resource('vault') self.old_request = None # Contains the last requested sequence if xdata(configuration, self.name, 'signal'): self.factoid_char = xdata(configuration, self.name, 'signal')[0] else: # The signal char will be assigned during the first _listen_ # execution. We can't do this now as here we don't know which it. self.factoid_char = None
def __init__(self): Plugin.__init__(self, 'info') if os.name == 'posix': self.operating_system = 'posix' self.topics = ('os', 'python', 'resources', 'running_for', 'signal_char', 'twisted', 'uptime', 'version') elif os.name == 'nt': self.operating_system = 'windows nt' self.topics = ('os', 'python', 'running_for', 'signal_char', 'twisted', 'version') else: self.topics = () self.launched_at = datetime.datetime.now() self._set_summary(_('Displays various information about P1tr and its \ environment')) self._add_command(_('info'), '<topic>', _('Specify in topic what \ kind of information you want to see. See help info topics.')) self._add_help_topic('topics', _('Available info topics: %s' % ', '.join(self.topics)))
def __init__(self): Plugin.__init__(self, 'dice') self._set_summary(_('Plugin for rolling various dices')) self._add_command( 'roll', '<expression>', _('makes P1tr roll one or \ more dices like specified in expression. expression should look like this: \ d6 or 2d20 or d3+7; d and the succeeding number are obligate and specify the \ dice type. The preceeding number specifies the number of rolls. You can \ append a small mathematical expression with one of the symbols +-*/. The \ results of multiple expressions get added. Limits: see "help dice limits"')) self._add_help_topic( 'limits', _('The number of rolls and the \ modification must not have more than 2 digits, number of sides is limited \ to three.')) self._add_command('dice', '<expression>', _('alias of roll. See \ "help dice roll" for help'))
def __init__(self): Plugin.__init__(self, 'topic') self._set_summary(_('Various functions for topic modification.')) self._add_command('topic', '<action> <text>', _('Performs action. \ Some actions require text as argument. See help topic actions.')) self._add_help_topic('actions', _('set <channel> <text>: sets topic \ to text; add <channel> <text>: appends text to topic; remove <channel> \ <index>: if no integer is given for index, the last item of the topic is \ being deleted, otherwise the "indexth" part of it; save <channel>: saves the \ current state of the topic; restore <channel>: restores a previously saved \ state of the topic; seperator <text>: sets text as seperator of the topic \ parts.')) self.resource = self._load_resource('topics') # self.resource dictionary structure: # {'_seperator': 'string', '#channel': ['part', 'part', 'part'], } # self.resource['#channel'] items represent the parts of a topic, # seperated by self.resource['_seperator']. if not self.resource: self.resource['_seperator'] = '::' self.resource.sync() self.sep = ' %s ' % self.resource['_seperator']
def __init__(self): Plugin.__init__(self, 'tracker') self._set_summary(_('Counts how often a word is mentioned. \ Case-sensitive. Words get counted only in one channel')) self._add_command('track', '<word>', _('Adds word to tracklist.')) self._add_command('untrack', '<word>', _('Removes word from \ tracklist.')) self._add_command('tracklist', '<channel>', _('Shows all tracked \ words for channel. If channel is not given, the words of the current one get \ displayed.')) self._add_command('trackstats', '<word>', _('Shows how often word \ was mentioned and the three people who mention it the most.')) self.resource = self._load_resource('resource') # Structure of self.resource dictionary: # {'server': {'channel': {'word': {'nick': int, }, }, }, } self.watched = [] # For better performance inside listener all words P1tr watches # anywhere are stored in self.watched. for server in self.resource: for channel in self.resource[server]: self.watched.extend(self.resource[server][channel].keys())
def __init__(self): Plugin.__init__(self, 'auth') self._set_summary(_('Authentification plugin')) self._add_command( 'auth', '<password>', _('Show that you are you by \ using your password from registration. Better do this using private \ adressing.')) self._add_command( 'register', '<password>', _('Registers your nick \ with password. Better do this using private adressing.')) self._add_command( 'set', '<user> <level>', _('Changes user\'s level \ to the indicated one, which can be an integer from 1 to 29.')) self._add_command( 'level', '[<user>]', _('Shows user\'s level, or \ yours if you specify no username.')) for user in User.users.values(): user.trusted = False
def test_apply_cutting_overlap(self): """Test Plugin.apply_cutting_overlap()!""" overlap = 20 plugin = Plugin() g = Graphic("arrow.svg") g.set_scale(HPGL.HPGL_SCALE, HPGL.HPGL_SCALE) paths = g.get_polyline() lengths = [] for path in paths: lengths.append(g.get_path_length(path=path)) plugin.apply_cutting_overlap(paths, overlap) for path, length in zip(paths, lengths): if path_is_closed(path): new_length = g.get_path_length(path=path) assert round(length + overlap, 10) == round(new_length, 10), "%s != %s" % (round( length + overlap, 10), round(new_length, 10)) else: assert round(length, 10) == round(new_length, 10), "%s != %s" % (round( length, 10), round(new_length, 10))
def __init__(self): Plugin.__init__(self, 'basics') self._set_summary(_('Plugin for basic IRC operations')) self._add_command('join', '<channel>', _('makes P1tr join channel')) self._add_command('part', '[<channel>]', _('makes P1tr part channel. \ If channel is not given he parts the current one.')) self._add_command('quit', None, _('shuts P1tr down.')) self._add_command('mode', '<mode> [<nick|mask>]', _('sets channel \ modes to mode; add nick or mask if required for the particular mode.')) self._add_command('opme', None, _('gives you op if P1tr is able to \ and you have the appropriate level')) self._add_command('lang', '<code>', _('set P1tr\'s language to code. \ Example: lang ca')) self._add_command('reload', None, _('reloads all plugins.')) self._add_command('restart', None, _('restarts the bot.')) self._add_command('ping', None, 'says pong.') self._add_command('say', '<channel> <message>', _('lets the bot say \ <message> in <channel>')) self._add_command('action', '<channel> <something>', _('lets the bot do \ <something> in <channel>')) self._add_command('nick', '<nickname>', _('changes P1tr\'s nick to \ nickname.'))
def __init__(self): Plugin.__init__(self, 'info') if os.name == 'posix': self.operating_system = 'posix' self.topics = ('os', 'python', 'resources', 'running_for', 'signal_char', 'twisted', 'uptime', 'version') elif os.name == 'nt': self.operating_system = 'windows nt' self.topics = ('os', 'python', 'running_for', 'signal_char', 'twisted', 'version') else: self.topics = () self.launched_at = datetime.datetime.now() self._set_summary( _('Displays various information about P1tr and its \ environment')) self._add_command( _('info'), '<topic>', _('Specify in topic what \ kind of information you want to see. See help info topics.')) self._add_help_topic( 'topics', _('Available info topics: %s' % ', '.join(self.topics)))
def load_plugins(self): logger.info("Loading slack plugins...") plugin_files = glob.glob(self.plugins_dir + os.sep + "**" + os.sep + "[!__]*.py", recursive=True) for plugin_path in plugin_files: relative_path = os.path.relpath(plugin_path, os.getcwd()) import_path = relative_path.replace(".py", "").replace(os.sep, ".") for event_type in self.event_types: plugin = Plugin(event_type, importlib.import_module(import_path)) if plugin.callback is not None: if hasattr(self.bolt, plugin.type): event_handler: callable = getattr( self.bolt, plugin.type) event_handler(plugin.keyword)(plugin.callback) self.plugins.append(plugin)
def __init__(self): Plugin.__init__(self, 'LPBugAnnounce') self._set_summary(_('Announces new bugs for a LP project')) self.projects = {} self.loop = self.warmup = None
def reportCiphersuite(self, cs): l = lambda p, msg=msg: p.reportCiphersuite(cs) l = lambda p, s=self, l=l: s._helper(p, l) Plugin.executeLambda(Output_Ciphersuites_Plugin, l)
def logError(self, msg): l = lambda p, msg=msg: p.logError(msg) l = lambda p, s=self, l=l: s._helper(p, l) Plugin.executeLambda(Output_Log_Plugin, l)
def __init__(self): Plugin.__init__(self, 'nickserv') self._set_summary( _('Plugin that provides authentication with NickServ'))
def main(): # load plugins plugins = Plugin.findPlugins() Plugin.loadPlugins(plugins) # prepare argument parser parser = argparse.ArgumentParser() parser.add_argument('-s', '--starttls', help='use STARTTLS for specific protocol', choices=starttls_supported, dest='starttls') parser.add_argument('-p', '--port', type=int, default=443, help='TCP port to be checked', dest='port') parser.add_argument('host', help='hostname or IP address of target system') Plugin.executeLambda(None, lambda p, parser=parser: p.prepareArguments(parser)) args = parser.parse_args() # create storage storage = Plugin_Storage() # init plugins Plugin.executeLambda(None, lambda p, stor=storage, args=args: p.init(stor, args)) # create connection object if args.starttls == 'ftp': connection = Connection_STARTTLS_FTP(args.host, args.port) elif args.starttls == 'smtp': connection = Connection_STARTTLS_SMTP(args.host, args.port) else: connection = Connection_TCP_Socket(args.host, args.port) # execute all active tests Plugin.executeLambda( Active_Test_Plugin, lambda p, c=connection, stor=storage: p.execute(c, stor)) # deinit plugins: Plugin.executeLambda(None, lambda p, stor=storage: p.deinit(stor))
def __init__(self): Plugin.__init__(self, 'logger') self._set_summary(_('Logging plugin; not intended to interact.')) self._add_command('quote')
def init(self, storage, args): super().init(storage, args) self.output = Plugin.getPlugin('Helper_Output_Plugin')
def __init__(self): Plugin.__init__(self, 'nickserv') self._set_summary(_('Plugin that provides authentication with NickServ'))
def __init__(self): Plugin.__init__(self, 'seen') self._set_summary( _('Just use "seen user" to get information about \ user\'s last action')) self._add_command('seen')
def __init__(self): Plugin.__init__(self, 'talkback') self._set_summary(_('Plugin to repeat what others say in a channel')) self._add_command('talkback', None, _('initiates talkback')) self._add_command('stfu', None, _('lets talkback shut up')) self.talk_back = False