Ejemplo n.º 1
0
    def connect(self, host, port, user):
        self.host = host
        self.port = int(port)
        self.user = user
        self.mumble = pymumble.Mumble(host=self.host,
                                      port=self.port,
                                      user=self.user,
                                      password=self.password)
        self.mumble.start()
        # self.mumble.is_ready()
        j = 0
        while self.mumble.users.myself is None and j < 10:
            time.sleep(.5)
            j += 1

        self.sender = SignalSlotHandler()
        self.mumble.callbacks.set_callback(
            pymumble.constants.PYMUMBLE_CLBK_TEXTMESSAGERECEIVED,
            self.on_message_recieved)
        self.mumble.callbacks.set_callback(
            pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED,
            self.on_sound_received)
        self.mumble.set_receive_sound(True)

        if self.mumble.users.myself is None:
            raise ConnectionError
Ejemplo n.º 2
0
    def __init__(self):
        self.mumbleUser = "******"
        self.mumbleHost = "192.168.101.112"
        self.mumblePwd = ""

        self.inputRate = 8000  # Hz
        self.inputDevice = "plughw:1,0"
        self.outputDevice = 0
        self.outputRate = 8000  # Hz

        self.muted = True
        self.deafened = True
        self.digitalVol = 1
        self.silence = 300  # Threshold to detect sound

        try:
            self.input = aa.PCM(aa.PCM_CAPTURE, aa.PCM_NORMAL,
                                self.inputDevice)
            self.input.setchannels(self.MUMBLE_CHANNELS)
            self.input.setrate(self.inputRate)
            self.input.setformat(self.ALSA_FORMAT)
            self.input.setperiodsize(self.AUDIO_LEN)
        except:
            print("No input device")
        else:
            self.muted = False

        try:
            self.output = aa.PCM(aa.PCM_PLAYBACK, self.outputDevice)
            self.output.setchannels(self.MUMBLE_CHANNELS)
            self.output.setrate(self.outputRate)
            self.output.setformat(self.ALSA_FORMAT)
            self.output.setperiodsize(self.AUDIO_LEN)
        except:
            print("No output device")
        else:
            self.deafened = False

        try:
            self.client = pymumble.Mumble(self.mumbleHost, self.mumbleUser,
                                          64738, self.mumblePwd, None, None,
                                          True, [], False)
            self.client.set_codec_profile("audio")
            #self.client.callbacks.set_callback(PYMUMBLE_CLBK_USERCREATED, self.user_created)
            #self.client.callbacks.set_callback(PYMUMBLE_CLBK_USERREMOVED, self.user_removed)
            self.client.callbacks.set_callback(PYMUMBLE_CLBK_SOUNDRECEIVED,
                                               self.sound_received)
            self.client.callbacks.set_callback(
                PYMUMBLE_CLBK_TEXTMESSAGERECEIVED, self.text_received)
            self.client.start()
            self.client.is_ready()
            self.client.set_receive_sound(True)
        except:
            print("No mumble server")

        threading.Thread.__init__(self)
Ejemplo n.º 3
0
 def __init__(self,
              host="127.0.0.1",
              port=64738,
              user="******",
              password=None,
              channel=None):
     self.mumble = pymumble.Mumble(host, user=user, password=password)
     self.channel = channel
     self.stop = False
     signal.signal(signal.SIGINT, lambda signal, frame: self.__stop())
Ejemplo n.º 4
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.config = configparser.ConfigParser(interpolation=None)
        self.config.read("configuration.ini", encoding='utf-8')

        parser = argparse.ArgumentParser(description='Bot for playing audio files on Mumble')
        parser.add_argument("-s", "--server", dest="host", type=str, required=True, help="The hostame of a mumble server")
        parser.add_argument("-u", "--user", dest="user", type=str, required=True, help="Username for the bot", default="botamusique")
        parser.add_argument("-P", "--password", dest="password", type=str, default="", help="Password if server requires one")
        parser.add_argument("-p", "--port", dest="port", type=int, default=64738, help="Port of the mumble server")
        parser.add_argument("-c", "--channel", dest="channel", type=str, default="", help="Starting channel for the bot")

        args = parser.parse_args()
        self.volume = self.config.getfloat('bot', 'volume')

        self.channel = args.channel
        var.current_music = None
        var.playlist = []
        var.user = args.user
        var.music_folder = self.config.get('bot', 'music_folder')
        var.filters = self.config['filters']
        var.filter_select = self.config.get('bot', 'filter')
        var.is_proxified = self.config.getboolean("bot", "is_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None

        interface.init_proxy()

        t = threading.Thread(target=start_web_interface)
        t.daemon = True
        t.start()

        self.mumble = pymumble.Mumble(args.host, user=args.user, port=args.port, password=args.password,
                                      debug=self.config.getboolean('debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received", self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # be sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 5
0
    def __init__(self, host, usr, pwd, rate):
        self.mumbleHost = host
        self.mumbleUsr = usr
        self.mumblePwd = pwd
        self.rate = rate
        self.volume = 2

        try:
            self.client = pymumble.Mumble(self.mumbleHost, self.mumbleUsr,
                                          64738, self.mumblePwd, None, None,
                                          True, [], False)
            self.client.set_codec_profile("audio")
            #self.client.set_loop_rate(0.01)
            #self.client.callbacks.set_callback(PYMUMBLE_CLBK_USERCREATED, self.user_created)
            #self.client.callbacks.set_callback(PYMUMBLE_CLBK_USERREMOVED, self.user_removed)
            self.client.callbacks.set_callback(
                PYMUMBLE_CLBK_TEXTMESSAGERECEIVED, self.text_received)
            self.client.start()
            self.client.is_ready()
        except:
            print("Unable to initialize mumble client")

        Thread.__init__(self)
Ejemplo n.º 6
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.config = configparser.ConfigParser(interpolation=None)
        self.config.read(
            os.path.join(os.path.abspath(os.path.dirname(__file__)),
                         "configuration.ini"))

        parser = argparse.ArgumentParser(
            description='Bot for playing radio streams on Mumble')
        parser.add_argument("-s",
                            "--server",
                            dest="host",
                            type=str,
                            required=True,
                            help="Hostname of the Mumble server")
        parser.add_argument("-u",
                            "--user",
                            dest="user",
                            type=str,
                            required=True,
                            help="Username for the bot, Default=abot")
        parser.add_argument("-P",
                            "--password",
                            dest="password",
                            type=str,
                            default="",
                            help="Server password, if required")
        parser.add_argument("-p",
                            "--port",
                            dest="port",
                            type=int,
                            default=64738,
                            help="Port for the Mumble server")
        parser.add_argument("-c",
                            "--channel",
                            dest="channel",
                            type=str,
                            default="",
                            help="Default channel for the bot")
        parser.add_argument("-C",
                            "--cert",
                            dest="certificate",
                            type=str,
                            default=None,
                            help="Certificate file")
        parser.add_argument("-q",
                            "--quiet",
                            dest="quiet",
                            action="store_true",
                            help="Log are quiet")

        args = parser.parse_args()
        self.volume = self.config.getfloat('bot', 'volume')
        self.channel = args.channel
        self.playing = False
        self.url = None
        self.exit = False
        self.nb_exit = 0
        self.thread = None

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        self.mumble = pymumble.Mumble(args.host,
                                      user=args.user,
                                      port=args.port,
                                      password=args.password,
                                      debug=self.config.getboolean(
                                          'debug', 'mumbleConnection'),
                                      certfile=args.certificate)
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        # self.set_comment()
        self.mumble.users.myself.unmute()  # be sure the bot is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)
        self.loop()
Ejemplo n.º 7
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.volume = var.config.getfloat('bot', 'volume')
        if db.has_option('bot', 'volume'):
            self.volume = var.db.getfloat('bot', 'volume')

        self.channel = args.channel

        # Set specific format for the log
        FORMAT = '%(asctime)s: %(message)s'
        if args.verbose:
            logging.basicConfig(format=FORMAT, level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S')
            logging.debug("Starting in DEBUG loglevel")
        elif args.quiet:
            logging.basicConfig(format=FORMAT, level=logging.ERROR, datefmt='%Y-%m-%d %H:%M:%S')
            logging.error("Starting in ERROR loglevel")
        else:
            logging.basicConfig(format=FORMAT, level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
            logging.info("Starting in INFO loglevel")

        # the playlist is... a list (Surprise !!)
        var.playlist = []

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface", "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.is_playing = False

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface, args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")

        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")

        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.certificate:
            certificate = args.certificate
        else:
            certificate = var.config.get("server", "certificate")

        if args.tokens:
            tokens = args.tokens
        else:
            tokens = var.config.get("server", "tokens")
            tokens = tokens.split(',')

        if args.user:
            self.username = args.user
        else:
            self.username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host, user=self.username, port=port, password=password, tokens=tokens,
                                      debug=var.config.getboolean('debug', 'mumbleConnection'), certfile=certificate)
        self.mumble.callbacks.set_callback("text_received", self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 8
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.volume = var.config.getfloat('bot', 'volume')
        self.channel = args.channel
        var.current_music = {}

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        ######
        ## Format of the Playlist :
        ## [("<type>","<path/url>")]
        ## types : file, radio, url, is_playlist, number_music_to_play
        ######

        ######
        ## Format of the current_music variable
        # var.current_music = { "type" : str,
        #                       "path" : str,                 # path of the file to play
        #                       "url" : str                   # url to download
        #                       "title" : str,
        #                       "user" : str,
        #                       "is_playlist": boolean,
        #                       "number_track_to_play": int,  # FOR PLAYLIST ONLY
        #                       "start_index" : int,          # FOR PLAYLIST ONLY
        #                       "current_index" : int}        # FOR PLAYLIST ONLY
        # len(var.current_music) = 6

        var.playlist = []

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.playing = False

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface,
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")
        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")
        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.user:
            username = args.user
        else:
            username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host,
                                      user=username,
                                      port=port,
                                      password=password,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 9
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.volume = var.config.getfloat('bot', 'volume')
        self.channel = args.channel
        var.current_music = None

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        ######
        ## Format of the Playlist :
        ## [("<type>","<path>")]
        ## [("<radio>","<luna>"), ("<youtube>","<url>")]
        ## types : file, radio, url
        ######

        ######
        ## Format of the current_music variable
        # len(var.current_music) = 4
        # var.current_music[0] = <Type>
        # var.current_music[1] = <url> if url of radio
        # var.current_music[2] = <title>
        # var.current_music[3] = <path> if url or file

        var.playlist = []

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface,
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        self.mumble = pymumble.Mumble(args.host,
                                      user=args.user,
                                      port=args.port,
                                      password=args.password,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 10
0
import pymumble.pymumble_py3 as pymumble
import time

client = pymumble.Mumble("192.168.101.112", "doorBot", 64738, "2putipus", None, None, True, [], False)
client.set_codec_profile("audio")
client.start()
client.is_ready()

time.sleep(30)

Ejemplo n.º 11
0
    def __init__(self):
        print("JJ Mumble Bot Initializing...")
        # Core access.
        GM.jjmumblebot = self
        # Initialize configs.
        GM.cfg.read(utils.get_config_dir())
        # Initialize up-time tracker.
        GM.start_seconds = time.time()
        # Initialize application logging.
        logging.getLogger('chardet.charsetprober').setLevel(logging.INFO)

        log_file_name = f"{GM.cfg['Bot_Directories']['LogDirectory']}/runtime.log"
        GM.logger = logging.getLogger("RuntimeLogging")
        GM.logger.setLevel(logging.DEBUG)

        handler = TimedRotatingFileHandler(log_file_name, when='midnight', backupCount=30)
        handler.setLevel(logging.INFO)
        log_formatter = logging.Formatter('%(asctime)s - [%(levelname)s] - %(message)s')
        handler.setFormatter(log_formatter)
        GM.logger.addHandler(handler)

        GM.logger.info("######################################")
        GM.logger.info("Initializing JJMumbleBot...")
        GM.logger.info("Application configs have been read successfully.")
        # Initialize system arguments.
        if sys.argv:
            for item in sys.argv:
                # Enable safe mode.
                if item == "-safe":
                    GM.safe_mode = True
                    print('Safe mode has been enabled.')
                    GM.logger.info("Safe mode has been enabled through system arguments.")
                # Enable debug mode.
                if item == "-debug":
                    GM.debug_mode = True
                    print('Debug mode has been enabled.')
                    GM.logger.info("Debug mode has been enabled through system arguments.")
                # Enable quiet mode.
                if item == "-quiet":
                    GM.quiet_mode = True
                    print('Quiet mode has been enabled.')
                    GM.logger.info("Quiet mode has been enabled through system arguments.")
                # Enable verbose mode.
                if item == "-verbose":
                    GM.verbose_mode = True
                    print('Verbose mode has been enabled.')
                    GM.logger.info("Verbose mode has been enabled through system arguments.")
        # Initialize command queue.
        cmd_queue_lim = int(GM.cfg['Main_Settings']['CommandQueueLimit'])
        self.command_queue = QueueHandler(cmd_queue_lim)
        # Initialize command history tracker.
        cmd_history_lim = int(GM.cfg['Main_Settings']['CommandHistoryLimit'])
        GM.cmd_history = CMDQueue(cmd_history_lim)
        # Run Debug Mode tests.
        if GM.debug_mode:
            self.config_debug()
        # Retrieve mumble client data from configs.
        server_ip = GM.cfg['Connection_Settings']['ServerIP']
        server_pass = GM.cfg['Connection_Settings']['ServerPassword']
        server_port = int(GM.cfg['Connection_Settings']['ServerPort'])
        user_id = GM.cfg['Connection_Settings']['UserID']
        user_cert = GM.cfg['Connection_Settings']['UserCertification']
        GM.logger.info("Retrieved server information from application configs.")
        # Set main logic loop tick rate.
        self.tick_rate = float(GM.cfg['Main_Settings']['CommandTickRate'])
        # Set multi-command limit.
        self.multi_cmd_limit = int(GM.cfg['Main_Settings']['MultiCommandLimit'])
        # Set the command token.
        self.cmd_token = GM.cfg['Main_Settings']['CommandToken']
        if len(self.cmd_token) != 1:
            print("ERROR: The command token must be a single character! Reverting to the default: '!' token.")
            GM.logger.critical(
                "ERROR: The command token must be a single character! Reverting to the default: '!' token.")
            self.cmd_token = '!'
        # Initialize mumble client.
        GM.mumble = pymumble.Mumble(server_ip, user=user_id, port=server_port, certfile=user_cert,
                                    password=server_pass)
        # Initialize mumble callbacks.
        GM.mumble.callbacks.set_callback("text_received", self.message_received)
        # Set mumble codec profile.
        GM.mumble.set_codec_profile("audio")
        # Create temporary directories.
        utils.make_directory(GM.cfg['Media_Directories']['TemporaryImageDirectory'])
        GM.logger.info("Initialized temporary directories.")
        # Create any missing permanent directories.
        utils.make_directory(GM.cfg['Media_Directories']['PermanentMediaDirectory'] + "sound_board/")
        utils.make_directory(GM.cfg['Media_Directories']['PermanentMediaDirectory'] + "images/")
        GM.logger.info("Initialized permanent directories.")
        # Setup privileges.
        pv.setup_privileges()
        GM.logger.info("Initialized user privileges.")
        # Setup aliases.
        aliases.setup_aliases()
        GM.logger.info("Initialized aliases.")
        # Initialize PGUI.
        GM.gui = PseudoGUI()
        GM.logger.info("Initialized pseudo graphical user interface.")
        # Initialize plugins.
        if GM.safe_mode:
            self.initialize_plugins_safe()
            self.tick_rate = 0.2
            GM.logger.info("Initialized plugins with safe mode.")
        else:
            self.initialize_plugins()
            GM.logger.info("Initialized plugins.")
        # Run a plugin callback test.
        self.plugin_callback_test()
        GM.logger.info("Plugin callback test successful.")
        print("JJ Mumble Bot initialized!\n")
        # Initialize the web interface.
        if GM.cfg.getboolean('Connection_Settings', 'EnableWebInterface'):
            from helpers.web_handler import init_web
            self.web_thr = threading.Thread(target=init_web)
            self.web_thr.start()
            reg_print("JJMumbleBot Web Service was initialized.")
            GM.logger.info("JJMumbleBot Web Service was initialized.")
        # Join the server after all initialization is complete.
        self.join_server()
        GM.logger.info("JJ Mumble Bot has fully initialized and joined the server.")
        self.loop()
Ejemplo n.º 12
0
import pymumble.pymumble_py3 as pymumble
import time

client = pymumble.Mumble("your mumble server", "DoorButler", 64738,
                         "your mumble password", None, None, True, [], False)
client.set_codec_profile("audio")
client.start()
client.is_ready()

time.sleep(30)
Ejemplo n.º 13
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.ctrl_caught)

        self.config = configparser.ConfigParser(interpolation=None)
        self.config.read("configuration.ini", encoding='latin-1')

        parser = argparse.ArgumentParser(
            description='Bot for playing radio stream on Mumble')
        parser.add_argument("-s",
                            "--server",
                            dest="host",
                            type=str,
                            required=True,
                            help="The server's hostame of a mumble server")
        parser.add_argument("-u",
                            "--user",
                            dest="user",
                            type=str,
                            required=True,
                            help="Username you wish, Default=abot")
        parser.add_argument("-P",
                            "--password",
                            dest="password",
                            type=str,
                            default="",
                            help="Password if server requires one")
        parser.add_argument("-p",
                            "--port",
                            dest="port",
                            type=int,
                            default=64738,
                            help="Port for the mumble server")
        parser.add_argument("-c",
                            "--channel",
                            dest="channel",
                            type=str,
                            default="",
                            help="Default chanel for the bot")
        parser.add_argument("-q",
                            "--quiet",
                            dest="quiet",
                            action="store_true",
                            help="Only Error logs")

        args = parser.parse_args()
        self.volume = self.config.getfloat('bot', 'volume')

        self.channel = args.channel
        var.current_music = None

        FORMAT = '%(asctime)s: %(message)s'
        if args.quiet:
            logging.basicConfig(format=FORMAT,
                                level=logging.ERROR,
                                datefmt='%Y-%m-%d %H:%M:%S')
        else:
            logging.basicConfig(format=FORMAT,
                                level=logging.DEBUG,
                                datefmt='%Y-%m-%d %H:%M:%S')

        ######
        ## Format of the Playlist :
        ## [("<type>","<path>")]
        ## [("<radio>","<luna>"), ("<youtube>","<url>")]
        ## types : file, radio, url
        ######

        ######
        ## Format of the current_music variable
        # len(var.current_music) = 4
        # var.current_music[0] = <Type>
        # var.current_music[1] = <url> if url of radio
        # var.current_music[2] = <title>
        # var.current_music[3] = <path> if url or file

        var.playlist = []

        var.user = args.user
        var.music_folder = self.config.get('bot', 'music_folder')
        var.is_proxified = self.config.getboolean("bot", "is_web_proxified")

        self.exit = False
        self.nb_exit = 0
        self.thread = None

        if self.config.getboolean("bot", "web_interface"):
            interface.init_proxy()
            t = threading.Thread(target=start_web_interface)
            t.daemon = True
            t.start()

        self.mumble = pymumble.Mumble(args.host,
                                      user=args.user,
                                      port=args.port,
                                      password=args.password,
                                      debug=self.config.getboolean(
                                          'debug', 'mumbleConnection'))
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.loop()
Ejemplo n.º 14
0
    def __init__(self, args):
        self.log = logging.getLogger("bot")
        self.log.info("bot: botamusique version %s, starting..." %
                      self.version)
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.cmd_handle = {}
        self.volume_set = var.config.getfloat('bot', 'volume')
        if var.db.has_option('bot', 'volume'):
            self.volume_set = var.db.getfloat('bot', 'volume')

        self.volume = self.volume_set

        if args.channel:
            self.channel = args.channel
        else:
            self.channel = var.config.get("server", "channel", fallback=None)

        if args.verbose:
            self.log.setLevel(logging.DEBUG)
            self.log.debug("Starting in DEBUG loglevel")
        elif args.quiet:
            self.log.setLevel(logging.ERROR)
            self.log.error("Starting in ERROR loglevel")

        var.user = args.user
        var.music_folder = util.solve_filepath(
            var.config.get('bot', 'music_folder'))
        var.tmp_folder = util.solve_filepath(
            var.config.get('bot', 'tmp_folder'))
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.thread_stderr = None
        self.is_pause = False
        self.pause_at_id = ""
        self.playhead = -1
        self.song_start_at = -1
        self.last_ffmpeg_err = ""
        self.read_pcm_size = 0
        # self.download_threads = []
        self.wait_for_downloading = False  # flag for the loop are waiting for download to complete in the other thread

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            tt = threading.Thread(target=start_web_interface,
                                  name="WebThread",
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            self.log.info('Starting web interface on {}:{}'.format(
                wi_addr, wi_port))
            tt.start()

        if var.config.getboolean("bot", "auto_check_update"):
            th = threading.Thread(target=self.check_update,
                                  name="UpdateThread")
            th.daemon = True
            th.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")

        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")

        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.channel:
            self.channel = args.channel
        else:
            self.channel = var.config.get("server", "channel")

        if args.certificate:
            certificate = args.certificate
        else:
            certificate = util.solve_filepath(
                var.config.get("server", "certificate"))

        if args.tokens:
            tokens = args.tokens
        else:
            tokens = var.config.get("server", "tokens")
            tokens = tokens.split(',')

        if args.user:
            self.username = args.user
        else:
            self.username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host,
                                      user=self.username,
                                      port=port,
                                      password=password,
                                      tokens=tokens,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'),
                                      certfile=certificate)
        self.mumble.callbacks.set_callback(
            pymumble.constants.PYMUMBLE_CLBK_TEXTMESSAGERECEIVED,
            self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        self.join_channel()
        self.mumble.set_bandwidth(200000)

        self.is_ducking = False
        self.on_ducking = False
        self.ducking_release = time.time()

        if not var.db.has_option("bot", "ducking") and var.config.getboolean("bot", "ducking", fallback=False)\
                or var.config.getboolean("bot", "ducking"):
            self.is_ducking = True
            self.ducking_volume = var.config.getfloat("bot",
                                                      "ducking_volume",
                                                      fallback=0.05)
            self.ducking_volume = var.db.getfloat("bot",
                                                  "ducking_volume",
                                                  fallback=self.ducking_volume)
            self.ducking_threshold = var.config.getfloat("bot",
                                                         "ducking_threshold",
                                                         fallback=5000)
            self.ducking_threshold = var.db.getfloat(
                "bot", "ducking_threshold", fallback=self.ducking_threshold)
            self.mumble.callbacks.set_callback(
                pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED,
                self.ducking_sound_received)
            self.mumble.set_receive_sound(True)

        # Debug use
        self._loop_status = 'Idle'
        self._display_rms = False
        self._max_rms = 0
Ejemplo n.º 15
0
    def __init__(self):
        signal.signal(signal.SIGINT, self.kill)

        self.playing = False
        self.stop_playing = False
        self.exit = False
        self.thread = None

        self.playlist = []
        self.skip = False
        self.remove = False
        self.playlist_playing = False

        self.config = configparser.ConfigParser(interpolation=None)
        self.config.read(
            os.path.join(os.path.abspath(os.path.dirname(__file__)),
                         "config.ini"))

        if self.config.get('bot', 'certfile').lower() == "none":
            self.mumblecert = None
        else:
            self.mumblecert = self.config.get('bot', 'certfile')

        if self.config.get('bot', 'keyfile').lower() == "none":
            self.mumblekey = None
        else:
            self.mumblekey = self.config.get('bot', 'keyfile')

        self.mumblecomment = self.config.get('bot', 'comment')
        self.volume = self.config.getfloat('bot', 'volume')

        self.playcmd = self.config.get('commands', 'play')
        self.stopcmd = self.config.get('commands', 'stop')
        self.addcmd = self.config.get('commands', 'add')
        self.removecmd = self.config.get('commands', 'remove')
        self.skipcmd = self.config.get('commands', 'skip')
        self.shufflecmd = self.config.get('commands', 'shuffle')
        self.volumecmd = self.config.get('commands', 'volume')
        self.mutecmd = self.config.get('commands', 'mute')
        self.unmutecmd = self.config.get('commands', 'unmute')
        self.joincmd = self.config.get('commands', 'join')
        self.helpcmd = self.config.get('commands', 'help')
        self.killcmd = self.config.get('commands', 'kill')
        self.flipcmd = self.config.get('commands', 'flip')
        self.rollcmd = self.config.get('commands', 'roll')
        self.customonecmd = self.config.get('commands', 'customcmdone')
        self.customtwocmd = self.config.get('commands', 'customcmdtwo')

        self.notices = self.config.getboolean('notifications', 'notices')
        self.playingnownotice = self.config.get('notifications', 'playingnow')
        self.invalidcommandnotice = self.config.get('notifications',
                                                    'invalidcommand')
        self.emptyplaylistnotice = self.config.get('notifications',
                                                   'emptyplaylist')
        self.invalidurlnotice = self.config.get('notifications', 'invalidurl')
        self.volumesetnotice = self.config.get('notifications', 'volumeset')
        self.volumehighnotice = self.config.get('notifications', 'volumehigh')
        self.volumeerrornotice = self.config.get('notifications',
                                                 'volumeerror')
        self.volumemutednotice = self.config.get('notifications',
                                                 'volumemuted')
        self.botmutednotice = self.config.get('notifications', 'botmuted')
        self.botunmutednotice = self.config.get('notifications', 'botunmuted')
        self.addedsongnotice = self.config.get('notifications', 'addedsong')
        self.skipsongnotice = self.config.get('notifications', 'skipsong')
        self.rfpnotice = self.config.get('notifications', 'removefromplaylist')
        self.shufflenotice = self.config.get('notifications',
                                             'shuffleplaylist')
        self.nowplayingnotice = self.config.get('notifications', 'nowplaying')
        self.stoppedplayingnotice = self.config.get('notifications',
                                                    'stoppedplaying')
        self.reqadminnotice = self.config.get('notifications', 'permission')
        self.helpnotice = self.config.get('notifications', 'help')
        self.customonenotice = self.config.get('notifications', 'custommsgone')
        self.customtwonotice = self.config.get('notifications', 'custommsgtwo')

        self.admins = self.config.get('other', 'admins').split(";")
        self.urlwhitelist = self.config.getboolean('other', 'urlwhitelist')
        self.whitelistedurls = self.config.get('other',
                                               'whitelistedurls').split(";")
        self.blacklistedurls = self.config.get('other',
                                               'blacklistedurls').split(";")
        self.filetypes = self.config.get('other',
                                         'allowedfiletypes').split(";")

        self.mumble = pymumble.Mumble(
            self.config.get('server', 'server'),
            user=self.config.get('bot', 'username'),
            port=self.config.getint('server', 'port'),
            reconnect=self.config.getboolean('bot', 'autoreconnect'),
            certfile=self.mumblecert,
            keyfile=self.mumblekey)
        self.mumble.callbacks.set_callback("text_received",
                                           self.message_received)
        self.mumble.set_codec_profile("audio")
        self.mumble.start()
        self.mumble.is_ready()
        self.mumble.users.myself.unmute()
        self.mumble.set_bandwidth(200000)
        self.mumble.users.myself.comment(self.mumblecomment)

        self.mainloop()
Ejemplo n.º 16
0
    def __init__(self, args):
        signal.signal(signal.SIGINT, self.ctrl_caught)
        self.cmd_handle = {}
        self.volume_set = var.config.getfloat('bot', 'volume')
        if var.db.has_option('bot', 'volume'):
            self.volume_set = var.db.getfloat('bot', 'volume')

        self.volume = self.volume_set

        self.channel = args.channel

        if args.verbose:
            root.setLevel(logging.DEBUG)
            logging.debug("Starting in DEBUG loglevel")
        elif args.quiet:
            root.setLevel(logging.ERROR)
            logging.error("Starting in ERROR loglevel")

        var.playlist = PlayList()

        var.user = args.user
        var.music_folder = var.config.get('bot', 'music_folder')
        var.is_proxified = var.config.getboolean("webinterface",
                                                 "is_web_proxified")
        self.exit = False
        self.nb_exit = 0
        self.thread = None
        self.is_playing = False
        self.is_pause = False
        self.playhead = -1
        self.song_start_at = -1

        if var.config.getboolean("webinterface", "enabled"):
            wi_addr = var.config.get("webinterface", "listening_addr")
            wi_port = var.config.getint("webinterface", "listening_port")
            interface.init_proxy()
            tt = threading.Thread(target=start_web_interface,
                                  args=(wi_addr, wi_port))
            tt.daemon = True
            tt.start()

        if args.host:
            host = args.host
        else:
            host = var.config.get("server", "host")

        if args.port:
            port = args.port
        else:
            port = var.config.getint("server", "port")

        if args.password:
            password = args.password
        else:
            password = var.config.get("server", "password")

        if args.certificate:
            certificate = args.certificate
        else:
            certificate = var.config.get("server", "certificate")

        if args.tokens:
            tokens = args.tokens
        else:
            tokens = var.config.get("server", "tokens")
            tokens = tokens.split(',')

        if args.user:
            self.username = args.user
        else:
            self.username = var.config.get("bot", "username")

        self.mumble = pymumble.Mumble(host,
                                      user=self.username,
                                      port=port,
                                      password=password,
                                      tokens=tokens,
                                      debug=var.config.getboolean(
                                          'debug', 'mumbleConnection'),
                                      certfile=certificate)
        self.mumble.callbacks.set_callback(
            pymumble.constants.PYMUMBLE_CLBK_TEXTMESSAGERECEIVED,
            self.message_received)

        self.mumble.set_codec_profile("audio")
        self.mumble.start()  # start the mumble thread
        self.mumble.is_ready()  # wait for the connection
        self.set_comment()
        self.mumble.users.myself.unmute()  # by sure the user is not muted
        if self.channel:
            self.mumble.channels.find_by_name(self.channel).move_in()
        self.mumble.set_bandwidth(200000)

        self.is_ducking = False
        self.on_ducking = False
        self.ducking_release = time.time()


        if not var.db.has_option("bot", "ducking") and var.config.getboolean("bot", "ducking", fallback=False)\
                or var.config.getboolean("bot", "ducking"):
            self.is_ducking = True
            self.ducking_volume = var.config.getfloat("bot",
                                                      "ducking_volume",
                                                      fallback=0.05)
            self.ducking_volume = var.db.getfloat("bot",
                                                  "ducking_volume",
                                                  fallback=self.ducking_volume)
            self.ducking_threshold = var.config.getfloat("bot",
                                                         "ducking_threshold",
                                                         fallback=5000)
            self.ducking_threshold = var.db.getfloat(
                "bot", "ducking_threshold", fallback=self.ducking_threshold)
            self.mumble.callbacks.set_callback(
                pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED,
                self.ducking_sound_received)
            self.mumble.set_receive_sound(True)