Esempio n. 1
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'))
    bot = RtmBot(config)
    try:
        bot.start()
    except KeyboardInterrupt:
        sys.exit(0)
Esempio n. 2
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)
Esempio n. 3
0
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()
Esempio n. 4
0
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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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()
Esempio n. 8
0
def init(config):
    global slack_client
    bot = RtmBot(config)
    slack_client = bot.slack_client
    return bot
Esempio n. 9
0
#!/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')
Esempio n. 10
0
from rtmbot import RtmBot
from os import path
from constants import path_conf_file
from logic.exceptions import NoConfFile
import yaml
"""
This python script is responsible for starting process of 
instant and periodical messages replay by our bot.
"""
if __name__ == '__main__':
    try:
        if not path.exists(path_conf_file):
            raise NoConfFile
        with open(path_conf_file, 'r') as conffile:
            conf = yaml.load(conffile)
        bot = RtmBot(conf)
        bot.start()
    except NoConfFile:
        raise NoConfFile(
            'There is no configuration file at the provided path.')
Esempio n. 11
0
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()
Esempio n. 12
0
from flask import Flask, redirect, url_for, render_template
from rtmbot import RtmBot
from threading import Thread
from average_bot.user import User

config = {
    "SLACK_TOKEN":
    os.environ["SLACK_API_TOKEN"],
    "ACTIVE_PLUGINS": [
        "average_bot.plugins.average_user_number.AvergaeUserNumberPlugin",
        "average_bot.plugins.average_all_numbers.AvergaeAllNumbersPlugin"
    ]
}

app = Flask(__name__)
bot = RtmBot(config)


@app.route("/")
def index():
    return redirect(url_for('average'))


@app.route("/average/")
def average():
    """
    Get the average for all the users
    """
    return render_template('average_all.html',
                           average=User.get_average_users())
Esempio n. 13
0
def run():
    bot = RtmBot(config)
    bot.start()
Esempio n. 14
0

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(open(args.config or 'rtmbot.conf', 'r'))
bot = RtmBot(config)
try:
    bot.start()
except KeyboardInterrupt:
    sys.exit(0)

import json
import os
import sys
import time
import logging

from slackclient import SlackClient

def dbg(debug_string):
    if debug:
Esempio n. 15
0
from rtmbot import RtmBot
import yaml
from config import rtmbot_config
from clients.sentry import create_client
import logging
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging

slack_client = RtmBot(rtmbot_config).slack_client
sentry_client = create_client()

# Manually specify a client

_handler = SentryHandler(sentry_client)

_handler.setLevel(logging.ERROR)

setup_logging(_handler)