def setup(self): ### Grab important shit self.commands = CommandManager() self.storage = StorageManager() ### Initial config load try: self._config = self.storage.get_file(self, "config", YAML, "plugins/jargon.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/jargon.yml") self.logger.error("Disabling...") self._disable_self() return ### Register commands self.commands.register_command("jargon", self.jargon_cmd, self, "jargon.jargon", default=True)
def setup(self): """ Called when the plugin is loaded. Performs initial setup. """ self.commands = CommandManager() self.commands.register_command("storage", self.storage_command, self, "management.storage", ["st", "files", "file"]) self.commands.register_command("protocols", self.protocols_command, self, "management.protocols", ["pr", "protos", "proto"]) self.commands.register_command("plugins", self.plugins_command, self, "management.plugins", ["pl", "plugs", "plug"]) self.commands.register_command("packages", self.packages_command, self, "management.packages", ["pa", "packs", "pack"]) self.commands.register_command("permissions", self.permissions_command, self, "management.permissions", ["pe", "perms", "perm"]) self.commands.register_command("users", self.users_command, self, "management.users", ["us", "user"]) self.commands.register_command("shutdown", self.shutdown_command, self, "management.shutdown")
class UrbanDictionaryPlugin(plugin.PluginObject): commands = None config = None def setup(self): ### Grab important shit self.commands = CommandManager() ### Register commands self.commands.register_command("urbandictionary", self.urbandictionary_cmd, self, "urbandictionary.definition", aliases=["ud"], default=True) def urbandictionary_cmd(self, protocol, caller, source, command, raw_args, parsed_args): args = raw_args.split() # Quick fix for new command handler signature ### Get LastFM username to use username = None if len(args) == 0: caller.respond("Usage: {CHARS}urbandictionary <term>") return term = " ".join(args) try: definition, permalink = self.get_definition(term) if definition is None: source.respond('[UD] "%s" is not defined yet' % term) else: # TODO: Limit definition length source.respond('[UD] "%s" - %s - (%s)' % (term, to_bytes(definition) .replace('\r', '') .replace('\n', ' '), to_bytes(permalink))) except: self.logger.exception("Cannot get definition for '%s'" % term) source.respond("There was an error while fetching the definition -" " please try again later, or alert a bot admin.") def get_definition(self, term): request = urllib2.Request("http://api.urbandictionary.com/v0/define?" + urllib.urlencode({'term': term})) # F**k you PEP8. F**k you with the largest, spikiest dragon d***o, in # every orifice you have, and more. request.add_header('User-agent', 'Mozilla/5.0 ' '(X11; U; Linux i686; ' 'en-US; rv:1.9.0.1) ' 'Gecko/2008071615 ' 'Fedora/3.0.1-1.fc9-1.fc9 ' 'Firefox/3.0.1') try: definition = json.load(urllib2.urlopen(request))["list"][0] return definition["definition"], definition["permalink"] except IndexError: return None, None
def setup(self): self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/wordnik.yml") except Exception: self.logger.exception("Unable to load the configuration!") return self._disable_self() if not self.config.exists: self.logger.error("Unable to find the configuration at " "config/plugins/wordnik.yml - Did you fill " "it out?") return self._disable_self() if "apikey" not in self.config or not self.config["apikey"]: self.logger.error("Unable to find an API key; did you fill out the" " config?") return self._disable_self() self._load() self.config.add_callback(self._load) self.plugman = PluginManager() self.commands = CommandManager() self.commands.register_command("dict", self.dict_command, self, "wordnik.dict", default=True) self.commands.register_command("wotd", self.wotd_command, self, "wordnik.wotd", default=True)
def setup(self): self.commands = CommandManager() self.commands.register_command("geoip", self.command, self, "geoip.command", default=True)
def setup(self): ### Grab important shit self.commands = CommandManager() self.storage = StorageManager() ### Initial config load try: self._config = self.storage.get_file(self, "config", YAML, "plugins/8ball.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/8ball.yml") self.logger.error("Disabling...") self._disable_self() return ### Setup some stuff self._random = random.Random() self._question_regex = re.compile("[\W_]+") ### Register commands self.commands.register_command("8ball", self.eight_ball_cmd, self, "8ball.8ball", default=True)
def setup(self): self.logger.trace("Entered setup method.") self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/minecraft.yml") except Exception: self.logger.exception("Error loading configuration!") self._disable_self() return if not self.config.exists: self.logger.error("Unable to find config/plugins/minecraft.yml") self.logger.error("Disabling..") self._disable_self() return if not self.relay_targets: self.logger.warn("No valid target protocols found. " "Disabling status relaying.") self.commands = CommandManager() self.commands.register_command("mcquery", self.query_command, self, "minecraft.query", default=True) if self.do_relay: reactor.callLater(30, self.start_relay)
def setup(self): self.logger.trace("Entered setup method.") self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/inter.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error(_("Disabling..")) self._disable_self() return if not self.config.exists: self.logger.error("Unable to find config/plugins/inter.yml") self.logger.error(_("Disabling..")) self._disable_self() return self.config.add_callback(self.reload) self.commands.register_command("players", self.players_command, self, "inter.players", default=True) if not reactor.running: self.events.add_callback( "ReactorStarted", self, self.first_load, 0 ) else: self.first_load()
def setup(self): self.logger.trace("Entered setup method.") self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/wolfram.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling..") self._disable_self() return if not self.config.exists: self.logger.error("Unable to find config/plugins/wolfram.yml") self.logger.error("Disabling..") self._disable_self() return self.commands = CommandManager() self._load() self.config.add_callback(self._load) self.commands.register_command("wolfram", self.wolfram_command, self, "wolfram.wolfram", aliases=["wa"], default=True)
class RoulettePlugin(plugin.PluginObject): commands = None channels = {} users = {} def setup(self): self.commands = CommandManager() self.commands.register_command("rroulette", self.play, self, "russianroulette.rroulette", aliases=["roulette"], default=True) def addChannel(self, channel): if channel not in self.channels.keys(): players = [] curplayers = [] shots = 0 deaths = 0 chambers = 6 data = {"players": players, "shots": shots, "deaths": deaths, "chambers": chambers, "curplayers": curplayers} self.channels[channel] = data def play(self, protocol, caller, source, command, raw_args, parsed_args): args = raw_args.split() # Quick fix for new command handler signature self.logger.trace("Caller: %s" % repr(caller)) self.logger.trace("Source: %s" % repr(source)) self.logger.trace("Result: %s" % isinstance(source, Channel)) if not isinstance(source, Channel): caller.respond("This command may only be used in a channel.") return self.addChannel(source.name) chambers_left = self.channels[source.name]["chambers"] random.seed() if random.randint(1, chambers_left) == 1: # Boom! source.respond("BANG") protocol.send_action(source, "*reloads the gun*") chambers_left = 6 source.respond( 'There are %s new chambers. You have a %s%% chance of dying.' % (chambers_left, int(100.0 / chambers_left))) else: # Click.. chambers_left -= 1 source.respond( '*click* You\'re safe for now. There are %s chambers left. ' 'You have a %s%% chance of dying.' % (chambers_left, int(100.0 / chambers_left))) self.channels[source.name]["chambers"] = chambers_left
def setup(self): self.commands = CommandManager() self.commands.register_command("hb", self.hb_command, self, "hb.hb", default=True)
def setup(self): """ Called when the plugin is loaded. Performs initial setup. """ self.commands = CommandManager() self.commands.register_command("page", self.page_command, self, default=True)
def setup(self): self.commands = CommandManager() self.commands.register_command("rroulette", self.play, self, "russianroulette.rroulette", aliases=["roulette"], default=True)
def __init__(self): self.commands = CommandManager() self.event_manager = EventManager() self.logger = getLogger("Manager") self.plugman = PluginManager(self) self.yapsy_logger = getLogger("yapsy") self.metrics = None
def setup(self): self.commands = CommandManager() self.commands.register_command("w3validate", self.w3validate, self, "w3.w3validate", aliases=["validate", "valid"], default=True)
def setup(self): self.commands = CommandManager() self.commands.register_command('armoury', self.armoury, self, 'wow.armoury', aliases=['armory'], default=True)
def setup(self): ### Grab important shit self.commands = CommandManager() ### Register commands self.commands.register_command("urbandictionary", self.urbandictionary_cmd, self, "urbandictionary.definition", aliases=["ud"], default=True)
def setup(self): ### Grab important shit self.commands = CommandManager() self.storage = StorageManager() ### Initial config load try: self._config = self.storage.get_file(self, "config", YAML, "plugins/aoshelper.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/aoshelper.yml") self.logger.error("Disabling...") self._disable_self() return ### Load options from config self._load() self._config.add_callback(self._load) ### Register commands self.commands.register_command("aosplayercount", self.playercount_cmd, self, "aoshelper.playercount", [ "playercount" ], default=True) self.commands.register_command("aostoip", self.aos_to_ip_command, self, "aoshelper.aostoip", [ "aos2ip" ]) self.commands.register_command("iptoaos", self.ip_to_aos_command, self, "aoshelper.iptoaos", [ "ip2aos" ]) ### Setup soem variables self._last_update_voxlap = 0 self._last_update_steam = 0 self._last_voxlap_player_count = -1 self._last_steam_player_count = -1
def setup(self): """ Called when the plugin is loaded. Performs initial setup. """ self.logger.trace(_("Entered setup method.")) self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/urls.yml") except Exception: self.logger.exception(_("Error loading configuration!")) else: if not self.config.exists: self.logger.warn(_("Unable to find config/plugins/urls.yml")) else: self.content_types = self.config["content_types"] self.spoofing = self.config["spoofing"] self.logger.debug(_("Spoofing: %s") % self.spoofing) self.channels = self.storage.get_file(self, "data", YAML, "plugins/urls/channels.yml") self.shortened = self.storage.get_file( self, "data", DBAPI, "sqlite3:data/plugins/urls/shortened.sqlite", "data/plugins/urls/shortened.sqlite", check_same_thread=False) self.commands = CommandManager() self.events = EventManager() self.reload() def message_event_filter(event=MessageReceived): target = event.target type_ = event.type return type_ == "message" \ or isinstance(target, Channel) \ or isinstance(target, User) self.add_shortener("tinyurl", self.tinyurl) self.events.add_callback("MessageReceived", self, self.message_handler, 1, message_event_filter) self.commands.register_command("urls", self.urls_command, self, "urls.manage") self.commands.register_command("shorten", self.shorten_command, self, "urls.shorten", default=True)
class ItemsPlugin(plugin.PluginObject): commands = None config = None data = None storage = None handler = None @property def storage_type(self): if self.config["storage"].lower() == "json": return "json" return "sqlite" def setup(self): self.commands = CommandManager() self.storage = StorageManager() self.logger.trace("Entered setup method.") try: self.config = self.storage.get_file(self, "config", YAML, "plugins/items.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.warn("Defaulting to SQLite for storage.") else: if not self.config.exists: self.logger.warn("Unable to find config/plugins/items.yml") self.logger.warn("Defaulting to SQLite for storage.") else: self.logger.info("Using storage type: %s" % self.storage_type) self._load() self.config.add_callback(self._load) self.commands.register_command("give", self.give_command, self, "items.give", default=True) self.commands.register_command("get", self.get_command, self, "items.get", default=True) def _load(self): if self.storage_type == "json": self.handler = JSONType(self, self.storage, self.logger) else: self.handler = SQLiteType(self, self.storage, self.logger) @RateLimiter(5, 0, 10) def give_command(self, *args, **kwargs): return self.handler.give_command(*args, **kwargs) @RateLimiter(5, 0, 10) def get_command(self, *args, **kwargs): return self.handler.get_command(*args, **kwargs)
def __init__(self, name, factory, config): NoChannelsProtocol.__init__(self, name, factory, config) self.name = name self.log = getLogger(self.name) self.event_manager = EventManager() self.command_manager = CommandManager() reactor.connectTCP(self.config["connection"]["host"], self.config["connection"]["port"], self.factory, 120)
class MemosPlugin(plugin.PluginObject): commands = None events = None storage = None # data = None # SQLite for a change def setup(self): self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() # self.data = self.storage.get_file(self, "data", SQLITE, # "plugins/memos/memos.sqlite") # with self.data as c: # # Multiline strings because of an IDE bug # c.execute("""CREATE TABLE IF NOT EXISTS memos # (to TEXT, from TEXT, memo TEXT)""") self.events.add_callback("PreMessageReceived", self, self.message_received, 0) self.commands.register_command("memo", self.memo_command, self, "memo.send", default=True) def save_memo(self, sender, recipient, memo): recipient = recipient.lower() # with self.data as c: # c.execute("""INSERT INTO memos VALUES (?, ?, ?)""", # (recipient, sender, memo)) def get_memos(self, recipient): recipient = recipient.lower() # with self.data as c: # c.execute("""SELECT * FROM memos WHERE from=?""", (recipient,)) # d = c.fetchall() # return d def message_received(self, event=PreMessageReceived): user = event.source target = event.target if isinstance(event.target, Channel) else user memos = self.get_memos(user.name) if memos: for memo in memos: sender = memo[1] text = memo[2] target.respond("Memo for %s (from %s): %s" % (user.name, sender, text)) def memo_command(self, protocol, caller, source, command, raw_args, parsed_args): args = raw_args.split() # Quick fix for new command handler signature raise NotImplementedError("This isn't done yet.")
def setup(self): """ The list of bridging rules """ self.commands = CommandManager() self.reload() self.commands.register_command("debug", self.debug_cmd, self, "debug.debug", aliases=["dbg"])
def setup(self): # ## Grab important shit self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() self.plugman = PluginManager() # ## Set up database self.database = self.storage.get_file( self, "data", DBAPI, "sqlite3:data/plugins/factoids.sqlite", "data/plugins/factoids.sqlite", check_same_thread=False ) self.database.add_callback(self.reload) self.reload() # ## Register commands # We have multiple possible permissions per command, so we have to do # permission handling ourselves self.commands.register_command("addfactoid", self.factoid_add_command, self, None) self.commands.register_command("setfactoid", self.factoid_set_command, self, None) self.commands.register_command("deletefactoid", self.factoid_delete_command, self, None, ["delfactoid"]) self.commands.register_command("getfactoid", self.factoid_get_command, self, None, default=True) # ## Register events self.events.add_callback("MessageReceived", self, self.message_handler, 1) self.events.add_callback("Web/ServerStartedEvent", self, self.web_routes, 1)
def setup(self): ### Grab important shit self.commands = CommandManager() self.storage = StorageManager() ### Initial config load try: self._config = self.storage.get_file(self, "config", YAML, "plugins/lastfm.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/lastfm.yml") self.logger.error("Disabling...") self._disable_self() return ### Same for the data file (nickname=>lastfmusername map) try: self._nickmap = self.storage.get_file( self, "data", YAML, "plugins/lastfm-nickmap.yml") except Exception: self.logger.exception("Error loading nickmap!") self.logger.error("Disabling...") self._disable_self() ### Load options from config and nick map from data self._load() self._config.add_callback(self._load) ### Register commands self.commands.register_command("nowplaying", self.nowplaying_cmd, self, "lastfm.nowplaying", aliases=["np"], default=True) self.commands.register_command("lastfmnick", self.lastfmnick_cmd, self, "lastfm.lastfmnick", default=True) self.commands.register_command("lastfmcompare", self.compare_cmd, self, "lastfm.compare", aliases=["musiccompare", "compare"], default=True)
class ExamplePlugin(plugin.PluginObject): # Create the plugin class """ Example plugin object """ commands = None def setup(self): """ Called when the plugin is loaded. Performs initial setup. """ # Get an instance of the command manager self.commands = CommandManager() # Register the command in our system self.commands.register_command( "example", # The name of the command self.example_command, # The command's function self, # This plugin # permission="example.example", # Required permission for command default=True # Whether this command should be available to all ) self.commands.register_command( # Another example command "example2", self.example_command, self, default=True) def example_command(self, protocol, caller, source, command, raw_args, args): """ Command handler for the example command """ if args is None: # You'll probably always want this, so you always have # arguments if quote-parsing fails args = raw_args.split() # Send to the channel source.respond("Hello, world! You ran the %s command!" % command) # Send to the user that ran the command caller.respond("Raw arguments: %s" % raw_args) caller.respond("Parsed arguments: %s" % args) # Send directly through the protocol protocol.send_msg(source.name, "Message through the protocol!")
def setup(self): ### Grab important shit self._commands = CommandManager() self._storage = StorageManager() ### Initial config load try: self._config = self._storage.get_file(self, "config", YAML, "plugins/xkcd.yml") except: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/xkcd.yml") self.logger.error("Disabling...") self._disable_self() return ### Same for the data files try: self._comic_cache = self._storage.get_file( self, "data", YAML, "plugins/xkcd/comic-cache.yml") except: self.logger.exception("Error loading comic-cache!") self.logger.error("Disabling...") self._disable_self() try: self._archive = self._storage.get_file(self, "data", YAML, "plugins/xkcd/archive.yml") except: self.logger.exception("Error loading archive!") self.logger.error("Disabling...") self._disable_self() ### Initial data file setup and stuff self._load() self._config.add_callback(self._load) self._comic_cache.add_callback(self._load) self._archive.add_callback(self._load) ### Register commands self._commands.register_command("xkcd", self.xkcd_cmd, self, "xkcd.xkcd", default=True)
class ExamplePlugin(plugin.PluginObject): # Create the plugin class """ Example plugin object """ commands = None def setup(self): """ Called when the plugin is loaded. Performs initial setup. """ # Get an instance of the command manager self.commands = CommandManager() # Register the command in our system self.commands.register_command( "example", # The name of the command self.example_command, # The command's function self, # This plugin # permission="example.example", # Required permission for command default=True # Whether this command should be available to all ) self.commands.register_command( # Another example command "example2", self.example_command, self, default=True ) def example_command(self, protocol, caller, source, command, raw_args, args): """ Command handler for the example command """ if args is None: # You'll probably always want this, so you always have # arguments if quote-parsing fails args = raw_args.split() # Send to the channel source.respond("Hello, world! You ran the %s command!" % command) # Send to the user that ran the command caller.respond("Raw arguments: %s" % raw_args) caller.respond("Parsed arguments: %s" % args) # Send directly through the protocol protocol.send_msg(source.name, "Message through the protocol!")
def setup(self): self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() # self.data = self.storage.get_file(self, "data", SQLITE, # "plugins/memos/memos.sqlite") # with self.data as c: # # Multiline strings because of an IDE bug # c.execute("""CREATE TABLE IF NOT EXISTS memos # (to TEXT, from TEXT, memo TEXT)""") self.events.add_callback("PreMessageReceived", self, self.message_received, 0) self.commands.register_command("memo", self.memo_command, self, "memo.send", default=True)
def setup(self): ### Grab important shit self._commands = CommandManager() self._storage = StorageManager() ### Initial config load try: self._config = self._storage.get_file(self, "config", YAML, "plugins/dice.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/dice.yml") self.logger.error("Disabling...") self._disable_self() return ### Register commands self._commands.register_command("roll", self.roll_cmd, self, "dice.roll", aliases=["dice"], default=True)
def setup(self): self.commands = CommandManager() self.storage = StorageManager() self.logger.trace("Entered setup method.") try: self.config = self.storage.get_file(self, "config", YAML, "plugins/items.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.warn("Defaulting to SQLite for storage.") else: if not self.config.exists: self.logger.warn("Unable to find config/plugins/items.yml") self.logger.warn("Defaulting to SQLite for storage.") else: self.logger.info("Using storage type: %s" % self.storage_type) self._load() self.config.add_callback(self._load) self.commands.register_command("give", self.give_command, self, "items.give", default=True) self.commands.register_command("get", self.get_command, self, "items.get", default=True) self.commands.register_command("items", self.count_command, self, "items.count", default=True)
def setup(self): ### Grab important shit self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() ### Initial config load try: self._config = self.storage.get_file(self, "config", YAML, "plugins/triggers.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/triggers.yml") self.logger.error("Disabling...") self._disable_self() return ### Register event handlers def _message_event_filter(event=MessageReceived): return isinstance(event.target, Channel) self.events.add_callback("MessageReceived", self, self.message_handler, 1, _message_event_filter) self.events.add_callback("ActionReceived", self, self.action_handler, 1, _message_event_filter)
def setup(self): self.logger.trace("Entered setup method.") self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/inter.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error(_("Disabling..")) self._disable_self() return if not self.config.exists: self.logger.error("Unable to find config/plugins/inter.yml") self.logger.error(_("Disabling..")) self._disable_self() return self.config.add_callback(self.reload) self.commands.register_command("players", self.players_command, self, "inter.players", default=True) self.events.add_callback("ReactorStarted", self, self.first_load, 0)
def setup(self): """The list of bridging rules""" self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() self.data = self.storage.get_file(self, "data", YAML, "plugins/dialectizer/settings.yml") self.events.add_callback("MessageSent", self, self.handle_msg_sent, 1) self.commands.register_command("dialectizer", self.dialectizer_command, self, "dialectizer.set", aliases=["dialectiser"])
def setup(self): self.commands = CommandManager() self.goslate = Goslate() self.commands.register_command( "translate", self.translate_command, self, "translate.translate", ["tr", "t"], True )
def __str__(self): manager = CommandManager() if manager.aliases: return "Aliases: %s" % ", ".join( ["%s: %s" % (x[0], x[1]) for x in manager.aliases.items()] ) return "Aliases: None"
def setup(self): # Define this so we have instances of everything we need self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() self.plugman = PluginManager() # Now run the actual setup function self.wrapper(self.clj_plugin.setup)()
def setup(self): ### Grab important shit self.commands = CommandManager() self.storage = StorageManager() ### Initial config load try: self._file_config = self.storage.get_file( self, "config", YAML, "plugins/jargon.yml" ) except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._file_config.exists: self.logger.error("Unable to find config/plugins/jargon.yml") self.logger.error("Disabling...") self._disable_self() return self._file_config.add_callback(self.load) self.load() ### Register commands self.commands.register_command( "jargon", self.jargon_cmd, self, JARGON_PERM, aliases=["generatesentence", "generate"], default=True ) self.commands.register_command( "jargonlist", self.jargonlist_cmd, self, JARGON_LIST_PERM, aliases=["generatesentencelist", "generatelist"], default=True )
def setup(self): self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() self.data = self.storage.get_file( self, "data", DBAPI, "sqlite3:data/plugins/lastseen/users.sqlite", "data/plugins/lastseen/users.sqlite", check_same_thread=False ) self.data.runQuery("CREATE TABLE IF NOT EXISTS users (" "user TEXT, " "protocol TEXT, " "at INTEGER)") self.commands.register_command("seen", self.seen_command, self, "seen.seen", default=True) # General events self.events.add_callback("PreMessageReceived", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_source_caller]) self.events.add_callback("PreCommand", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_source_caller]) self.events.add_callback("NameChanged", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) self.events.add_callback("UserDisconnected", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) # Mumble events self.events.add_callback("Mumble/UserRemove", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) self.events.add_callback("Mumble/UserJoined", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) self.events.add_callback("Mumble/UserMoved", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) self.events.add_callback("Mumble/UserSelfMuteToggle", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) self.events.add_callback("Mumble/UserSelfDeafToggle", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller]) self.events.add_callback("Mumble/UserRecordingToggle", self, self.event_handler, 0, cancelled=True, extra_args=[self.event_user_caller])
class HeartbleedPlugin(plugin.PluginObject): commands = None def setup(self): self.commands = CommandManager() self.commands.register_command("hb", self.hb_command, self, "hb.hb", default=True) @run_async_threadpool def hb_command(self, protocol, caller, source, command, raw_args, parsed_args): args = raw_args.split() # Quick fix for new command handler signature if len(args) < 1: caller.respond("Usage: {CHARS}hb <address> [port]") return else: host = args[0] port = 443 if len(args) > 1: port = args[1] try: port = int(port) except: source.respond("Port '%s' is invalid, trying on port " "443." % port) try: source.respond("Checking %s:%s" % (host, port)) result = hb.try_host(host, port) if result: source.respond("Host %s is vulnerable!" % host) elif result is None: source.respond("Host %s returned an error. It's probably " "not vulnerable." % host) else: source.respond("Host %s is not vulnerable." % host) except: self.logger.exception("Error querying host %s" % host) source.respond("Unable to determine whether host %s is " "vulnerable." % host)
def setup(self): """ Called when the plugin is loaded. Performs initial setup. """ self.logger.trace(_("Entered setup method.")) self.storage = StorageManager() try: self.config = self.storage.get_file(self, "config", YAML, "plugins/urls.yml") except Exception: self.logger.exception(_("Error loading configuration!")) else: if not self.config.exists: self.logger.warn(_("Unable to find config/plugins/urls.yml")) else: self.content_types = self.config["content_types"] self.spoofing = self.config["spoofing"] self.logger.debug(_("Spoofing: %s") % self.spoofing) self.channels = self.storage.get_file(self, "data", YAML, "plugins/urls/channels.yml") self.shortened = self.storage.get_file( self, "data", DBAPI, "sqlite3:data/plugins/urls/shortened.sqlite", "data/plugins/urls/shortened.sqlite", check_same_thread=False ) self.commands = CommandManager() self.events = EventManager() self.reload() def message_event_filter(event=MessageReceived): target = event.target type_ = event.type return type_ == "message" \ or isinstance(target, Channel) \ or isinstance(target, User) self.add_shortener("tinyurl", self.tinyurl) self.events.add_callback("MessageReceived", self, self.message_handler, 1, message_event_filter) self.commands.register_command("urls", self.urls_command, self, "urls.manage") self.commands.register_command("shorten", self.shorten_command, self, "urls.shorten", default=True)
class TranslatePlugin(PluginObject): commands = None goslate = None def setup(self): self.commands = CommandManager() self.goslate = Goslate() self.commands.register_command( "translate", self.translate_command, self, "translate.translate", ["tr", "t"], True ) @run_async_threadpool def translate_command(self, protocol, caller, source, command, raw_args, parsed_args): if len(parsed_args) < 2: caller.respond( "Usage: {CHARS}" + command + " <languages> <text>" ) return langs = parsed_args[0] text = u" ".join([to_unicode(x) for x in parsed_args[1:]]) if u":" in langs: split = langs.split(u":") from_lang, to_lang = split[0], split[1] else: from_lang, to_lang = u"", langs try: translation = self.goslate.translate(text, to_lang, from_lang) source.respond(u"[{}] {}".format(to_lang, translation)) except Error as e: source.respond(u"Translation error: {}".format(e)) except Exception as e: self.logger.exception("Translation error") source.respond(u"Translation error: {}".format(e))
def __init__(self, name, factory, config): NoChannelsProtocol.__init__(self, name, factory, config) self.log = getLogger(self.name) self.event_manager = EventManager() self.command_manager = CommandManager() reactor.connectTCP( self.config["connection"]["host"], self.config["connection"]["port"], self.factory, 120 )
def setup(self): ### Grab important shit self.commands = CommandManager() self.storage = StorageManager() ### Initial config load try: self._config = self.storage.get_file(self, "config", YAML, "plugins/lastfm.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self._config.exists: self.logger.error("Unable to find config/plugins/lastfm.yml") self.logger.error("Disabling...") self._disable_self() return ### Same for the data file (nickname=>lastfmusername map) try: self._nickmap = self.storage.get_file(self, "data", YAML, "plugins/lastfm-nickmap.yml") except Exception: self.logger.exception("Error loading nickmap!") self.logger.error("Disabling...") self._disable_self() ### Load options from config and nick map from data self._load() self._config.add_callback(self._load) ### Register commands self.commands.register_command("nowplaying", self.nowplaying_cmd, self, "lastfm.nowplaying", aliases=["np"], default=True) self.commands.register_command("lastfmnick", self.lastfmnick_cmd, self, "lastfm.lastfmnick", default=True) self.commands.register_command("lastfmcompare", self.compare_cmd, self, "lastfm.compare", aliases=["musiccompare", "compare"], default=True)
class GeoIPPlugin(plugin.PluginObject): commands = None api_url = "http://freegeoip.net/json/%s" def setup(self): self.commands = CommandManager() self.commands.register_command("geoip", self.command, self, "geoip.command", default=True) def command(self, protocol, caller, source, command, raw_args, parsed_args): args = raw_args.split() # Quick fix for new command handler signature if len(args) < 1: caller.respond("Usage: {CHARS}geoip <address>") else: addr = urllib.quote_plus(args[0]) resp = urllib.urlopen(self.api_url % addr) data = resp.read() self.logger.trace("Data: %s" % repr(data)) if data == "Not Found\n": source.respond("%s | Not found" % args[0]) else: parsed = json.loads(data) country = parsed["country_name"] region = parsed["region_name"] city = parsed["city"] if not country and not city and not region: source.respond("%s | Not found" % args[0]) source.respond("%s | %s, %s, %s" % (args[0], city or "???", region or "???", country or "???"))
def setup(self): ### Grab important shit self.commands = CommandManager() self.events = EventManager() self.storage = StorageManager() ### Initial config load try: self.config = self.storage.get_file(self, "config", YAML, "plugins/drunkoctopus.yml") except Exception: self.logger.exception("Error loading configuration!") self.logger.error("Disabling...") self._disable_self() return if not self.config.exists: self.logger.error("Unable to find config/plugins/drunkoctopus.yml") self.logger.error("Disabling...") self._disable_self() return ### Create vars and stuff self._sobering_call = None self._drunktalk = DrunkTalk() ### Load options from config self._load() self.config.add_callback(self._load) ### Register events and commands self.events.add_callback("MessageSent", self, self.outgoing_message_handler, 1) self.commands.register_command("drunkenness", self.drunkenness_command, self, "drunkoctopus.drunkenness", default=True) self.commands.register_command("drink", self.drink_command, self, "drunkoctopus.drink")