def __init__(self, bot, configkey, RequestHandler=IncomingRequestHandler, extra_metadata={}): self.uid = False self.plugin_name = False self.bot = self._bot = bot self.configkey = configkey self.RequestHandler = RequestHandler self.load_configuration(configkey) self.setup_plugin() if not self.plugin_name: logger.warning("plugin_name not defined in code, not running") return if not self.uid: self.uid = "{}-{}".format(self.plugin_name, WebFramework.instance_number) WebFramework.instance_number = WebFramework.instance_number + 1 extra_metadata.update({"bridge.uid": self.uid}) self._handler_broadcast = plugins.register_handler( self._broadcast, type="sending", extra_metadata=extra_metadata) self._handler_repeat = plugins.register_handler( self._repeat, type="allmessages", extra_metadata=extra_metadata) self.start_listening(bot)
def _initialise(bot): # unbreak slackrtm memory.json usage # previously, this plugin wrote into "user_data" key to store its internal team settings _slackrtm_conversations_migrate_20170319(bot) # Start and asyncio event loop loop = asyncio.get_event_loop() slack_sink = bot.get_config_option('slackrtm') threads = [] if isinstance(slack_sink, list): for sinkConfig in slack_sink: # start up slack listener in a separate thread t = SlackRTMThread(bot, loop, sinkConfig) t.daemon = True t.start() t.isFullyLoaded.wait() threads.append(t) logger.info("%d sink thread(s) started", len(threads)) plugins.register_handler(_handle_membership_change, type="membership") plugins.register_handler(_handle_rename, type="rename") plugins.register_admin_command([ "slacks", "slack_channels", "slack_listsyncs", "slack_syncto", "slack_disconnect", "slack_setsyncjoinmsgs", "slack_setimageupload", "slack_sethotag", "slack_users", "slack_setslacktag", "slack_showslackrealnames", "slack_showhorealnames" ]) plugins.register_user_command(["slack_identify"]) plugins.start_asyncio_task(_wait_until_unloaded).add_done_callback( _plugin_unloaded)
def _initialise(Handlers, bot): if bot: _start_api(bot) plugins.register_handler(_handle_incoming_message, type="allmessages") else: print("API could not be initialized.") return []
async def _register_handlers(self): """register the handlers to send and receive messages""" await plugins.tracking.start({'module.path': self.uid}) self._closed = False plugins.register_handler(self._broadcast, "sending") plugins.register_handler(self._repeat, "message") plugins.tracking.end()
def __init__(self, bot, configkey, RequestHandler=IncomingRequestHandler, extra_metadata={}): self.uid = False self.plugin_name = False self.bot = self._bot = bot self.configkey = configkey self.RequestHandler = RequestHandler self.load_configuration(configkey) self.setup_plugin() if not self.plugin_name: logger.warning("plugin_name not defined in code, not running") return if not self.uid: self.uid = "{}-{}".format(self.plugin_name, WebFramework.instance_number) WebFramework.instance_number = WebFramework.instance_number + 1 extra_metadata.update({ "bridge.uid": self.uid }) self._handler_broadcast = plugins.register_handler(self._broadcast, type="sending", extra_metadata=extra_metadata) self._handler_repeat = plugins.register_handler(self._repeat, type="allmessages", extra_metadata=extra_metadata) self.start_listening(bot)
def _initialise(bot): global EXTSMTPUSER,EXTSMTPPWD,EXTSMTPSERVER,EXTSMTPPORT,INTSMTPADDRESS,INTSMTPPORT global CAMMAILCID global ALARMSYSURL,ALARMSYSUSR,ALARMSYSPWD,ALARMNOTURL,ALARMSUBJECTFORMAT,ALARMSYSOFFREGEXP global CAMPWD,CAMUSR,CAMURLS try: EXTSMTPUSER = bot.get_config_option("extsmtpuser") or None EXTSMTPPWD = bot.get_config_option("extsmtppwd") or None EXTSMTPSERVER = bot.get_config_option("extsmtpserver") or "smtp.gmail.com" EXTSMTPPORT = bot.get_config_option("extsmtpport") or "587" INTSMTPADDRESS = bot.get_config_option("intsmtpaddress") or socket.gethostname() INTSMTPPORT = int(bot.get_config_option("intsmtpport") or "10025") CAMMAILCID = bot.get_config_option("cammailCID") or None ALARMSYSURL = bot.get_config_option("alarmsysurl") or None ALARMSYSUSR = bot.get_config_option("alarmsysusr") or None ALARMSYSPWD = bot.get_config_option("alarmsyspwd") or None ALARMNOTURL = bot.get_config_option("alarmnoturl") or None ALARMSYSOFFREGEXP = re.compile(bot.get_config_option("alarmsysoffregexp")) or None s = bot.get_config_option("alarmsubjectformat") or { "regexp": r"(.*) (.*)( .*)*", "locationindex": 2 } ALARMSUBJECTFORMAT= { "regexp" : re.compile(s["regexp"]), "locationindex": s["locationindex"] } CAMPWD = bot.get_config_option("campwd") or None CAMUSR = bot.get_config_option("camusr") or None CAMURLS = bot.get_config_option("camurls") or {} except: logger.exception("missing config file entry") logger.info("using ALARMSUBJECTFORMAT: " + str(ALARMSUBJECTFORMAT)) global mybot mybot = bot # spawn a separate thread for the mail server # hoping asyncore and asyncio do not fight t = threading.Thread(target = smtpthread) t.daemon = True t.start() plugins.register_user_command(["interceptCamMail"]) plugins.register_handler(_handle_incoming_message, type="message")
def _initialize(bot): """Hangoutsbot plugin initialization function""" plugins.register_handler(_received_message, type="message", priority=50) #plugins.register_user_command(["getid"]) #plugins.register_admin_command(["addrelay","delrelay","relaydump"]) CLIENT.hangouts_bot = bot _start_discord_account(bot) _init_discord_map(bot)
def _initialise(bot): _start_slack_sinks(bot) plugins.register_handler(_broadcast, type="sending") plugins.register_handler(_repeat, type="allmessages") return [] plugins.register_user_command(["slackusers"])
def _initialise(bot): if not bot.get_config_option("botalive"): return plugins.register_admin_command(["dumpwatermarklogs"]) plugins.start_asyncio_task(_tick) # track events that can modify the watermark watch_event_types = ["message", "membership", "rename"] for event_type in watch_event_types: plugins.register_handler(_conv_external_event, event_type)
def _initialise(bot): convert_legacy_config(bot) plugins.register_user_command(["slack_identify"]) plugins.register_admin_command(["slack_sync", "slack_unsync"]) root = bot.get_config_option("slackrtm") or {} Base.bot = bot for team, config in root.get("teams", {}).items(): Base.add_slack(Slack(team, config["token"])) for sync in root.get("syncs", []): Base.add_bridge(BridgeInstance(bot, "slackrtm", sync)) for slack in Base.slacks.values(): slack.start() plugins.register_handler(on_membership_change, type="membership")
def __init__(self, bot, configkey, RequestHandler=IncomingRequestHandler): self._bot = bot self.bot = bot self.configkey = configkey self.RequestHandler = RequestHandler if not self.load_configuration(bot, configkey): logger.info("no configuration for {}, not running".format(self.configkey)) return self._start_sinks(bot) plugins.register_handler(self._handle_websync)
def _initialise(bot): if not bot.get_config_option("botalive"): return plugins.register_admin_command(["dumpwatermarklogs"]) plugins.start_asyncio_task(_tick) # track events that can modify the watermark watch_event_types = [ "message", "membership", "rename" ] for event_type in watch_event_types: plugins.register_handler(_conv_external_event, event_type)
def __init__(self, bot, configkey, RequestHandler=IncomingRequestHandler): self.bot = self._bot = bot self.configkey = configkey self.RequestHandler = RequestHandler self.configuration = bot.get_config_option(self.configkey) if not self.configuration: logger.info("no configuration for {}, not running".format( self.configkey)) return self._start_sinks(bot) plugins.register_handler(self._handle_websync)
def _initialise(bot): """update the sources, register the admin command and watch for messages Args: bot: HangupsBot instance """ if not bot.memory.exists(['passcode_relay']): bot.memory.set_by_path(['passcode_relay'], {}) if not bot.memory.exists(['passcode_relay', '_available_relays']): bot.memory.set_by_path(['passcode_relay', '_available_relays'], {}) asyncio.ensure_future(_update_relays(bot)) plugins.register_admin_command(['passcode_relay']) plugins.register_handler(_on_hangouts_message, "allmessages")
def _initialise(bot): if not _telesync_config(bot): return if not bot.memory.exists(['telesync']): bot.memory.set_by_path(['telesync'], {'ho2tg': {}, 'tg2ho': {}}) bot.memory.save() if not bot.memory.exists(['profilesync']): bot.memory.set_by_path(['profilesync'], {'ho2tg': {}, 'tg2ho': {}}) bot.memory.save() global client_session global tg_bot global tg_loop client_session = aiohttp.ClientSession() tg_bot = TelegramBot(bot) tg_bot.set_on_message_callback(tg_on_message) tg_bot.set_on_photo_callback(tg_on_photo) tg_bot.set_on_sticker_callback(tg_on_sticker) tg_bot.set_on_user_join_callback(tg_on_user_join) tg_bot.set_on_user_leave_callback(tg_on_user_leave) tg_bot.set_on_location_share_callback(tg_on_location_share) tg_bot.set_on_supergroup_upgrade_callback(tg_on_supergroup_upgrade) tg_bot.add_command("/whoami", tg_command_whoami) tg_bot.add_command("/whereami", tg_command_whereami) tg_bot.add_command("/setsyncho", tg_command_set_sync_ho) tg_bot.add_command("/clearsyncho", tg_command_clear_sync_ho) tg_bot.add_command("/addadmin", tg_command_add_bot_admin) tg_bot.add_command("/removeadmin", tg_command_remove_bot_admin) tg_bot.add_command("/syncprofile", tg_command_sync_profile) tg_bot.add_command("/unsyncprofile", tg_command_unsync_profile) tg_bot.add_command("/getme", tg_command_get_me) tg_loop = MessageLoop(tg_bot) plugins.start_asyncio_task(tg_loop.run_forever()) plugins.start_asyncio_task(tg_bot.setup_bot_info()) plugins.register_admin_command(["telesync"]) plugins.register_user_command(["syncprofile"]) plugins.register_handler(_on_membership_change, type="membership")
def _initialise(bot): global EXTSMTPUSER, EXTSMTPPWD, EXTSMTPSERVER, EXTSMTPPORT, INTSMTPADDRESS, INTSMTPPORT global CAMMAILCID global ALARMSYSURL, ALARMSYSUSR, ALARMSYSPWD, ALARMNOTURL, ALARMSUBJECTFORMAT, ALARMSYSOFFREGEXP global CAMPWD, CAMUSR, CAMURLS try: EXTSMTPUSER = bot.config.get_option("extsmtpuser") or None EXTSMTPPWD = bot.config.get_option("extsmtppwd") or None EXTSMTPSERVER = bot.config.get_option( "extsmtpserver") or "smtp.gmail.com" EXTSMTPPORT = bot.config.get_option("extsmtpport") or "587" INTSMTPADDRESS = bot.config.get_option( "intsmtpaddress") or socket.gethostname() INTSMTPPORT = int(bot.config.get_option("intsmtpport") or "10025") CAMMAILCID = bot.config.get_option("cammailCID") or None ALARMSYSURL = bot.config.get_option("alarmsysurl") or None ALARMSYSUSR = bot.config.get_option("alarmsysusr") or None ALARMSYSPWD = bot.config.get_option("alarmsyspwd") or None ALARMNOTURL = bot.config.get_option("alarmnoturl") or None ALARMSYSOFFREGEXP = re.compile( str(bot.config.get_option("alarmsysoffregexp"))) or None s = bot.config.get_option("alarmsubjectformat") or { "regexp": r"(.*) (.*)( .*)*", "locationindex": 2 } ALARMSUBJECTFORMAT = { "regexp": re.compile(s["regexp"]), "locationindex": s["locationindex"] } CAMPWD = bot.config.get_option("campwd") or None CAMUSR = bot.config.get_option("camusr") or None CAMURLS = bot.config.get_option("camurls") or {} except: logger.exception("missing config file entry") return logger.info("using ALARMSUBJECTFORMAT: " + str(ALARMSUBJECTFORMAT)) global mybot mybot = bot # spawn a separate thread for the mail server # hoping asyncore and asyncio do not fight t = threading.Thread(target=smtpthread) t.daemon = True t.start() plugins.register_user_command(["interceptCamMail"]) plugins.register_handler(_handle_incoming_message, type="message")
def _initialise(bot): global _bot, client _bot = bot token = bot.get_config_option('discord_token') if not token: logger.error("discord_token not set") return plugins.register_handler(_handle_hangout_message, type="allmessages") plugins.register_user_command(["dusers"]) plugins.register_admin_command(['dsync', 'discordfwd','discordfwdfilter']) try: client.run(token) except RuntimeError: # client.run will try start an event loop, however this will fail as hangoutsbot will have already started one # this isn't anything to worry about pass
def _initialize(bot): global tz_def # Read configuration information and initialize accordingly. plugin_conf = bot.config.get_by_path(["timeme"]) if not plugin_conf: plugin_conf = {"default_tz": [0, 0]} bot.config.set_by_path(["timeme"], plugin_conf) bot.config.save() default_tz = plugin_conf["default_tz"] tz_def = timezone(timedelta(hours=default_tz[0], minutes=default_tz[1])) # Debugging information, for sanity's sake. logger.info("Default timezone offset: {}".format(tz_def)) # Command registration protocols plugins.register_handler(_handle_timeme_action, type="message") plugins.register_user_command(["timeme"])
def _initialise(bot): if not _telesync_config(bot): return if not bot.memory.exists(['telesync']): bot.memory.set_by_path(['telesync'], {'ho2tg': {}, 'tg2ho': {}}) bot.memory.save() if not bot.memory.exists(['profilesync']): bot.memory.set_by_path(['profilesync'], {'ho2tg': {}, 'tg2ho': {}}) bot.memory.save() global tg_bot tg_bot = TelegramBot(bot) tg_bot.set_on_message_callback(tg_on_message) tg_bot.set_on_photo_callback(tg_on_photo) tg_bot.set_on_sticker_callback(tg_on_sticker) tg_bot.set_on_user_join_callback(tg_on_user_join) tg_bot.set_on_user_leave_callback(tg_on_user_leave) tg_bot.set_on_location_share_callback(tg_on_location_share) tg_bot.set_on_supergroup_upgrade_callback(tg_on_supergroup_upgrade) tg_bot.add_command("/whoami", tg_command_whoami) tg_bot.add_command("/whereami", tg_command_whereami) tg_bot.add_command("/setsyncho", tg_command_set_sync_ho) tg_bot.add_command("/clearsyncho", tg_command_clear_sync_ho) tg_bot.add_command("/addadmin", tg_command_add_bot_admin) tg_bot.add_command("/removeadmin", tg_command_remove_bot_admin) tg_bot.add_command("/tldr", tg_command_tldr) tg_bot.add_command("/syncprofile", tg_command_sync_profile) tg_bot.add_command("/unsyncprofile", tg_command_unsync_profile) tg_bot.add_command("/getme", tg_command_get_me) plugins.start_asyncio_task(tg_bot.message_loop(timeout=50)) plugins.start_asyncio_task(tg_bot.setup_bot_info()) plugins.register_admin_command(["telesync"]) plugins.register_user_command(["syncprofile"]) plugins.register_handler(_on_membership_change, type="membership")
def _initialise(bot): _migrate_syncroom_v1(bot) plugins.register_admin_command(["syncusers"]) plugins.register_handler(_handle_syncrooms_broadcast, type="sending") plugins.register_handler(_handle_incoming_message, type="message") plugins.register_handler( _handle_syncrooms_membership_change, type="membership")
def _initialise(bot): _migrate_syncroom_v1(bot) plugins.register_admin_command(["syncusers"]) plugins.register_handler(_handle_syncrooms_broadcast, type="sending") plugins.register_handler(_handle_incoming_message, type="message") plugins.register_handler(_handle_syncrooms_membership_change, type="membership")
def _initialise(bot): fileWriter = file_writer(bot) if fileWriter.initialised: plugins.register_handler(fileWriter.on_membership_change, type="membership") plugins.register_handler(fileWriter.on_rename, type="rename") plugins.register_handler(fileWriter.on_chat_message, type="allmessages")
def _initialize(bot): bot.spawn_lock = asyncio.Lock() config = bot.get_config_option("spawn") if not config: return cmds = config.get("commands") # override the load logic and register our commands directly get_location = False for cmd, cnf in cmds.items(): command.register(_spawn, admin=True, final=True, name=cmd) if cnf.get("allow_location"): get_location = True logger.info("spawn - %s", ", ".join(['*' + cmd for cmd in cmds])) plugins.register_admin_command(list(cmds)) if get_location: global _MAP_MATCH _MAP_MATCH = re.compile(config.get("map_regex", _MAP_REGEX), re.IGNORECASE|re.MULTILINE) plugins.register_handler(_location_handler, type="message")
def _initialise(bot): load() plugins.register_handler(_handle_bad_words, type='message') plugins.register_handler(_handle_bad_names, type='rename') plugins.register_handler(_handle_toxicity, type='message') plugins.register_user_command(['language', 'lastword', 'analyze']) plugins.register_admin_command(['langadd', 'langdel', 'langload']) plugins.register_user_command(['koby'])
def _initialise(bot): # unbreak slackrtm memory.json usage # previously, this plugin wrote into "user_data" key to store its internal team settings _slackrtm_conversations_migrate_20170319(bot) # Start and asyncio event loop loop = asyncio.get_event_loop() slack_sink = bot.get_config_option('slackrtm') threads = [] if isinstance(slack_sink, list): for sinkConfig in slack_sink: # start up slack listener in a separate thread t = SlackRTMThread(bot, loop, sinkConfig) t.daemon = True t.start() t.isFullyLoaded.wait() threads.append(t) logger.info("%d sink thread(s) started", len(threads)) plugins.register_handler(_handle_membership_change, type="membership") plugins.register_handler(_handle_rename, type="rename") plugins.register_admin_command([ "slacks", "slack_channels", "slack_listsyncs", "slack_syncto", "slack_disconnect", "slack_setsyncjoinmsgs", "slack_setimageupload", "slack_sethotag", "slack_users", "slack_setslacktag", "slack_showslackrealnames", "slack_showhorealnames" ]) plugins.register_user_command([ "slack_identify" ]) plugins.start_asyncio_task(_wait_until_unloaded).add_done_callback(_plugin_unloaded)
def _initialise(bot): utils._conversation_list_cache = convmem # !!!: it works, but i don't like it ;P _memory_load(bot) _update_conversation_list(bot) plugins.register_admin_command(["dumpconv"]) plugins.register_handler(_watch_message, type="allmessages") plugins.register_handler(_watch_rename, type="rename") plugins.register_handler(_watch_member, type="membership") plugins.register_shared('convmem.removeconv', _conv_remove)
def _initialise(bot): plugins.register_handler(_broadcast, type="sending") plugins.register_handler(_repeat, type="message") #_register_chatbridge_behaviour('userlist', _syncout_users) plugins.register_admin_command(["syncusers"]) return [] plugins.register_handler(_handle_syncrooms_membership_change, type="membership")
def _initialise(bot): _migrate_syncroom_v1(bot) plugins.register_handler(_broadcast, type="sending") plugins.register_handler(_repeat, type="allmessages") #_register_chatbridge_behaviour('userlist', _syncout_users) plugins.register_admin_command(["syncusers"]) return [] plugins.register_handler(_handle_syncrooms_membership_change, type="membership")
def _initialise(): plugins.register_handler(_handle_keyword) plugins.register_user_command(["subscribe", "unsubscribe"])
def _initialise(): plugins.register_user_command(["xkcd"]) plugins.register_handler(_watch_xkcd_link, type="message")
def _initialise(bot): _start_slack_sinks(bot) plugins.register_handler(_handle_slackout) plugins.register_user_command(["slackusers"])
def _initialise(): plugins.register_handler(_reddit_links, type="message")
def _initialise(bot): _migrate_mention_config_to_memory(bot) plugins.register_handler(_handle_mention, "message") plugins.register_user_command( ["pushbulletapi", "setnickname", "bemorespecific"]) plugins.register_admin_command(["mention"])
def _initialise(bot): _load_all_the_things() plugins.register_admin_command(["redditmemeword"]) plugins.register_handler(_scan_for_triggers)
def _initialise(bot): plugins.register_handler(on_message, type="message", priority=5)
def _initialise(): plugins.register_handler(_handle_forwarding, type="message")
def _initialise(bot): plugins.register_handler(_watch_rename, type="rename") plugins.register_admin_command(["topic"])
def _initialise(bot): plugins.register_handler(_watch_new_adds, type="membership") plugins.register_admin_command(["addmod", "delmod"])
def _initialise(bot): plugins.register_handler(_watch_image_link, type="message")
def _initialise(bot): plugins.register_handler(_handle_message, type="message") plugins.register_user_command(["directionshelp"])
def _initialise(bot): plugins.register_handler(_watch_membership_change, type="membership")
def _initialise(bot): plugins.register_handler(_handle_incoming_message, type="message") plugins.register_user_command(["chat"]) plugins.register_admin_command(["chatreset"])
def _initialise(): plugins.register_handler(_handle_join_notify, "membership")
def _initialise(bot): plugins.register_admin_command(["invite"]) plugins.register_user_command(["rsvp"]) plugins.register_handler(_issue_invite_on_exit, type="membership")
def _initialise(): plugins.register_handler(_watch_new_adds, type="membership") plugins.register_admin_command(["addmod", "delmod"])
def _initialise(bot): plugins.register_handler(_handle_incoming_message, type="message") plugins.register_user_command(["chat"])
def _initialise(): plugins.register_handler(_watch_image_link, type="message")
def _initialise(bot): plugins.register_handler(_handle_join_notify, type="membership")
def _initialise(bot): plugins.register_handler(_handle_incoming_message, type="message") plugins.register_user_command(["chat"]) plugins.register_handler(_scan_for_triggers)
def _initialise(bot): plugins.register_handler(_handle_me_action) plugins.register_user_command(["diceroll", "coinflip"])
def _initialise(bot): _migrate_mention_config_to_memory(bot) plugins.register_handler(_handle_mention, "message") plugins.register_user_command(["pushbulletapi", "setnickname", "bemorespecific"]) plugins.register_admin_command(["mention"])
def _initialise(bot): plugins.register_handler(on_watermark_update, type="watermark") plugins.register_handler(on_typing_notification, type="typing")
def _initialise(bot): plugins.register_handler(on_hangout_call, type="call")