Ejemplo n.º 1
0
def main():
    """The bot's main entry point.

    | Initialize the bot and start processing messages.
    """
    config_file = path.join(path.dirname(__file__), 'config.cfg')
    if not path.exists(config_file):
        logging.info("Setting up config file")
        config.do_setup(config_file)
        return
    botconfig = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
    with open(config_file) as f:
        botconfig.read_file(f)
    bot = IrcBot(botconfig)
    try:
        bot.start()
    except KeyboardInterrupt:
        # KeyboardInterrupt means someone tried to ^C, so shut down the bot
        bot.disconnect('Bot received a Ctrl-C')
        bot.shutdown_mp()
        sys.exit(0)
    except Exception as ex:
        bot.shutdown_mp(False)
        logging.error("The bot died! %s" % ex)
        output = "".join(traceback.format_exc())
        for line in output.split('\n'):
            logging.error(line)
        sys.exit(1)
Ejemplo n.º 2
0
Archivo: core.py Proyecto: N6UDP/cslbot
def init(confdir="/etc/cslbot"):
    """The bot's main entry point.

    | Initialize the bot and start processing messages.
    """
    multiprocessing.set_start_method('spawn')

    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--debug', help='Enable debug logging.', action='store_true')
    args = parser.parse_args()
    loglevel = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=loglevel)

    bot = IrcBot(confdir)

    try:
        bot.start()
    except KeyboardInterrupt:
        # KeyboardInterrupt means someone tried to ^C, so shut down the bot
        bot.disconnect('Bot received a Ctrl-C')
        bot.shutdown_mp()
        sys.exit(0)
    except Exception as ex:
        bot.shutdown_mp(False)
        logging.error("The bot died! %s" % ex)
        output = "".join(traceback.format_exc()).strip()
        for line in output.split('\n'):
            logging.error(line)
        sys.exit(1)
Ejemplo n.º 3
0
def main():
    """The bot's main entry point.

    | Initialize the bot and start processing messages.
    """
    config_file = path.join(path.dirname(__file__), 'config.cfg')
    if not path.exists(config_file):
        logging.info("Setting up config file")
        config.do_setup(config_file)
        return
    botconfig = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
    with open(config_file) as f:
        botconfig.read_file(f)
    bot = IrcBot(botconfig)
    try:
        bot.start()
    except KeyboardInterrupt:
        # KeyboardInterrupt means someone tried to ^C, so shut down the bot
        bot.disconnect('Bot received a Ctrl-C')
        bot.shutdown_mp()
        sys.exit(0)
    except Exception as ex:
        bot.shutdown_mp(False)
        logging.error("The bot died! %s" % ex)
        output = "".join(traceback.format_exc())
        for line in output.split('\n'):
            logging.error(line)
        sys.exit(1)
Ejemplo n.º 4
0
def main():
    args = get_args()
    setup_logging()
    bot = FidiBot(args.channel, args.nickname, args.server, args.port,
                  realname= args.realname, password=args.password, callsign=args.callsign)
    setup_client_logging(bot)
    try:
        bot.start()
    except KeyboardInterrupt:
        bot.disconnect(_("Someone closed me!"))
    except Exception as e:
        log.exception(e)
        bot.disconnect(_("I crashed damn it!"))
        raise SystemExit(4)
Ejemplo n.º 5
0
def main():
    with open("client.txt") as cl:
        client = cl.read()
    with open("token.txt") as tok:
        token = tok.read()
    username = "******"
    channel = "codetoad"
    bot = Bot(username, client, token, channel)
    try:
        bot.start()
    except KeyboardInterrupt:
        bot.disconnect()
        print()
        exit()
Ejemplo n.º 6
0
def main():
  try:
    import config
  except Exception as e:
    print u"Could not import config"
    print e
    exit(1)

  bot = LogBot(config)
  try:
    bot.start()
  except KeyboardInterrupt:
    print "Now dying..."
    bot.save_config()
    bot.db.save()
    bot.disconnect(u"Death by console")
    print "Dead."
Ejemplo n.º 7
0
def main():
    config = configparser.ConfigParser()
    config.read("config.cfg")

    obs = config["obs"]
    ws = obswebsocket.obsws(obs["host"], int(obs["port"]), obs["password"])

    twitch = config["twitch"]
    commands = config["scenes"]
    try:
        bot = TwitchBot(twitch["username"], twitch["token"], twitch["channel"],
                        ws, commands)
        bot.start()
    except KeyboardInterrupt:
        print("Ctrl-C")
        bot.ws.disconnect()
        bot.disconnect()
        sys.exit(0)
Ejemplo n.º 8
0
def main(args):
    banner()

    slackServers = []
    configFp = None

    try:
        configName = args[0] if len(args) else "config.json"
        configFp = open(configName, "r")
    except IOError:
        usage()

    config = json.load(configFp)
    configFp.close()

    # load slack servers
    for i in config["servers"]:
        slackServers.append(
            SlackServer(
                i["url"],
                i["name"],
                i["username"],
                i["channel"],
                (i["batch_time"],
                 i["batch_amount"])))

    # load irc info
    server = config["irc_server"]
    port = config["irc_port"]
    channel = config["irc_channel"]
    nickname = config["irc_nick"]
    accepted_nick = config["accepted_nick"]
    testing = config["testing"]

    bot = TbSlack(channel, nickname, server,
                  port, slackServers, accepted_nick, testing)

    try:
        bot.start()
    except KeyboardInterrupt:
        print("Disconnecting on user Ctrl-C")
        bot.disconnect()
Ejemplo n.º 9
0
def start_irc_bot(verbose=True, debug=False):
    if debug:
        logging.basicConfig(level=logging.DEBUG)
        # only the first basicConfig() is respected.
    if verbose:
        logging.basicConfig(level=logging.INFO)
    pyb = pyborg.pyborg.pyborg
    bot = ModIRC(pyb)
    try:
        bot.start()
    except KeyboardInterrupt:
        bot.my_pyborg.save_all()
        bot.disconnect("Killed at terminal.")
    except IOError as e:
        if bot.settings['multiplex']:
            logging.error(e)
            logging.info("Is pyborg_http running?")
        else:
            raise
    except Exception as e:
        logging.exception(e)
        bot.my_pyborg.save_all()
        bot.disconnect("Caught exception")
Ejemplo n.º 10
0
def main():
    # Set up config
    config = ConfigParser.ConfigParser()
    config.read('main.cfg')

    server   =     config.get('irc', 'server')
    port     = int(config.get('irc', 'port'))
    channel  =     config.get('irc', 'channel')
    nickname =     config.get('irc', 'nick')
    
    # Start the bot!
    bot = BitfighterLogBot(config, channel, nickname, server, port)
    
    try:
        bot.our_start()
    except KeyboardInterrupt:
        pass
    except SystemExit:
        pass
    except:
        traceback.print_exc()
        sys.exit(0)

    bot.disconnect(config.get('irc', 'quit_message'))
Ejemplo n.º 11
0
def start_irc_bot(verbose=True, debug=False, conffile="example.irc.toml"):
    if debug:
        logging.basicConfig(level=logging.DEBUG)
        # only the first basicConfig() is respected.
    if verbose:
        logging.basicConfig(level=logging.INFO)
    pyb = pyborg.pyborg.pyborg
    settings = toml.load(conffile)
    if settings['multiplex']:
        try:
            check_server()
        except requests.exceptions.ConnectionError:
            logger.error("Connection to pyborg server failed!")
            print("Is pyborg_http running?")
            sys.exit(2)

    bot = ModIRC(pyb, settings)
    # Tell the bot to load commands
    bot.scan()
    logging.debug("Command Registry: %s", bot.registry.registered)
    try:
        bot.start()
    except KeyboardInterrupt:
        bot.teardown()
        bot.disconnect("Killed at terminal.")
    except IOError as e:
        if bot.settings['multiplex']:
            logger.error(e)
            logger.info("Is pyborg_http running?")
        else:
            raise
    except Exception as e:
        logger.exception(e)
        bot.teardown()
        bot.disconnect("Caught exception")
        raise e
Ejemplo n.º 12
0
def main():
    # Set up config
    config = ConfigParser.ConfigParser()
    config.read('main.cfg')

    server = config.get('irc', 'server')
    port = int(config.get('irc', 'port'))
    channel = config.get('irc', 'channel')
    nickname = config.get('irc', 'nick')

    # Start the bot!
    bot = BitfighterLogBot(config, channel, nickname, server, port)

    try:
        bot.our_start()
    except KeyboardInterrupt:
        pass
    except SystemExit:
        pass
    except:
        traceback.print_exc()
        sys.exit(0)

    bot.disconnect(config.get('irc', 'quit_message'))
Ejemplo n.º 13
0
def end_vote():
    global bot
    bot.disconnect()
Ejemplo n.º 14
0
                   query + '")')
        payload = {
            'key': self.config['google']['key'],
            'cx': self.config['google']['engine'],
            'num': 1,
            'fields': 'items(link,snippet)',
            'q': query
        }
        request = requests.get('https://www.googleapis.com/customsearch/v1',
                               params=payload)
        result = request.json()
        try:
            self.msg(
                '#' + target,
                bold('[Google] ') + underline(result['items'][0]['link']) +
                ' : ' +
                itallic(result['items'][0]['snippet'].replace('\n', ' ')))
        except:
            self.msg('#' + target, bold('[Google] ') + 'Aucun résultat.')


if __name__ == "__main__":

    # start the bot
    bot = ModIRC(sys.argv)
    try:
        bot.our_start()
    except:
        traceback.print_exc()
    bot.disconnect("Bye :(")
Ejemplo n.º 15
0
 def on_int(signal, frame):
     bot.disconnect()
     time.sleep(5) # allow for parting Stack Exchange chat message to be sent
Ejemplo n.º 16
0
            print e.message, e.args
            
    # handle when a txt2speech "say" command complete
    def on_speech_end(self, name, completed):
        # since we're not using the built pyttsx loop, we need this
        self.engine.iterate()
    
    # handle text-to-speech errors    
    def on_speech_error(self, name, exception):
        print exception.msg, exception.args
while 1:
    # TODO: this is crap, we need better try/excepts
    try:
        bot = IRCNotifier("#pibot", "raspBot", "108.59.11.230", BUTTON, RED_LED, YELLOW_LED, GREEN_LED, "kptkommie", TXT2SPEECH)
        
        # set timer for button state checking
        bot.reactor.execute_every(.2, bot.check_button)
        
        # "start" the txt2speech loop
        bot.engine.startLoop(False)
        
        # start the main bot loop
        bot.start()
        
           
    finally:
        bot.disconnect("RasPi IRC Notifier 0.1")
        bot.engine.endLoop()
        GPIO.cleanup()
        bot.die()
Ejemplo n.º 17
0
class MashiroBot(irc.bot.SingleServerIRCBot):
	def __init__(self):
		# read configuration file
		config = RawConfigParser()
		config.read('conf/config.ini')

		# get server information from the configuration file
		self.server = config.get("irc", "server")
		self.port = int(config.get("irc", "port"))
		self.nickname = config.get("irc", "nickname")
		self.realname = config.get("irc", "realname")
		self.nspasswd = config.get("nickserv", "passwd")
		self.channel = config.get("irc", "channel")
		self.reconnection_interval = config.get("misc", "reconnection_interval")

		irc.bot.SingleServerIRCBot.encoding = 'utf-8'
		irc.bot.SingleServerIRCBot.__init__(self, [(self.server, self.port)], self.nickname, self.realname, self.reconnection_interval)

	def on_welcome(self, server, e):
		message = e.arguments[0]
		print(message)
		server.join(self.channel)

if __name__ == '__main__':
    bot = MashiroBot()
    try:
        bot.start()
    except KeyboardInterrupt:
        bot.disconnect()
        exit(1)