def start_bot(token): print("Starting bot for token: {}".format(token)) config = { "DEBUG": True, "SLACK_TOKEN": token, "ACTIVE_PLUGINS": ["plugins.runner.FeedsparqPlugin"], "FeedsparqPlugin": {"DEBUG": True} } print("The config file: {}".format(config)) bot = RtmBot(config) bot.start()
def main(args=None): # load args with config path if not specified if not args: args = parse_args() config = yaml.load(open(args.config or 'rtmbot.conf', 'r')) bot = RtmBot(config) try: bot.start() except KeyboardInterrupt: sys.exit(0)
def main(): logging.basicConfig(filename='slackbot.log', level=logging.DEBUG) logger = logging.getLogger() bot = RtmBot(rtmbot_config) try: bot.start() except KeyboardInterrupt: sys.exit(0) except Exception as e: logger.error('Error when run bot', exc_info=True)
def main(args=None): # load args with config path if not specified if not args: args = parse_args() config = yaml.safe_load(open(args.config or 'rtmbot.conf', 'r')) bot = RtmBot(config) try: bot.start() except KeyboardInterrupt: sys.exit(0)
def main(args=None): # load args with config path if not specified if not args: args = parse_args() config = yaml.load(open(args.config or 'rtmbot.conf', 'r')) config['SLACK_TOKEN'] = os.environ['SLACK_TOKEN'] bot = RtmBot(config) try: bot.start() except KeyboardInterrupt: sys.exit(0)
def main(args=None): # load args with config path if not specified if not args: args = parse_args() if os.environ.get('DEBUG'): DEBUG_MODE = str2bool(os.environ.get('DEBUG')) else: DEBUG_MODE = args.debug config = { 'DEBUG': DEBUG_MODE, 'SLACK_TOKEN': os.environ.get('SLACK_TOKEN') or args.slack_token, 'LOGFILE': os.environ.get('LOG_PATH') or args.log_path, 'ACTIVE_PLUGINS': ['plugins.tagger.Tagger'], 'Tagger': { 'BOT_DEFAULT_USERNAME': os.environ.get('BOT_DEFAULT_USERNAME') or args.bot_default_username, } } if config['SLACK_TOKEN'] is None: print( 'SLACK_TOKEN is not set! Define it in environment variable or provide as run argument --slack_token=YOUR_SLACK_TOKEN' ) sys.exit(1) if config['Tagger']['BOT_DEFAULT_USERNAME'] is None: print( 'BOT_DEFAULT_USERNAME is not set! Define it in environment variable or provide as run argument --bot_default_username=default_username' ) sys.exit(2) bot = RtmBot(config) try: bot.start() except KeyboardInterrupt: sys.exit(0)
from rtmbot import RtmBot from rtmbot.core import Plugin # secret라는 module에 있는 SLACK_TOKEN을 불러오는 코드 import secret # chatlogic이라는 module에 있는 Reply의 logic pattern을 불러오는 코드 import menulogic class HelloPlugin(Plugin): def process_message(self, data): answer = menulogic.reply(data["text"]) if answer is None: pass else: self.outputs.append([data["channel"], answer]) config = { "SLACK_TOKEN": secret.SLACK_TOKEN, "ACTIVE_PLUGINS": ["main.HelloPlugin"] } bot = RtmBot(config) bot.start()
#!/usr/bin/env python from argparse import ArgumentParser import yaml from rtmbot import RtmBot def parse_args(): parser = ArgumentParser() parser.add_argument( '-c', '--config', help='Full path to config file.', metavar='path' ) return parser.parse_args() # load args with config path args = parse_args() config = yaml.load(file(args.config or 'rtmbot.conf', 'r')) bot = RtmBot(config) try: bot.start() except KeyboardInterrupt: sys.exit(0) except: logging.exception('OOPS')
def main(): """ Run the bot, (run this function only if you want to run the bot without the web wedpoints) """ bot = RtmBot(config) bot.start()
def run(): bot = RtmBot(config) bot.start()