Lot of new features
Web interface almost ready, better bot
This commit is contained in:
63
mumbleBot.py
63
mumbleBot.py
@ -18,6 +18,7 @@ import variables as var
|
||||
import hashlib
|
||||
import youtube_dl
|
||||
import media
|
||||
import logging
|
||||
|
||||
|
||||
class MumbleBot:
|
||||
@ -33,6 +34,7 @@ class MumbleBot:
|
||||
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')
|
||||
@ -40,6 +42,12 @@ class MumbleBot:
|
||||
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>")]
|
||||
@ -59,16 +67,17 @@ class MumbleBot:
|
||||
|
||||
var.user = args.user
|
||||
var.music_folder = self.config.get('bot', 'music_folder')
|
||||
var.is_proxified = self.config.getboolean("bot", "is_proxified")
|
||||
var.is_proxified = self.config.getboolean("bot", "is_web_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()
|
||||
if args.web_interace:
|
||||
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'))
|
||||
@ -86,11 +95,11 @@ class MumbleBot:
|
||||
self.loop()
|
||||
|
||||
def ctrl_caught(self, signal, frame):
|
||||
print("\ndeconnection asked")
|
||||
logging.info("\ndeconnection asked")
|
||||
self.exit = True
|
||||
self.stop()
|
||||
if self.nb_exit > 1:
|
||||
print("Forced Quit")
|
||||
logging.info("Forced Quit")
|
||||
sys.exit(0)
|
||||
self.nb_exit += 1
|
||||
|
||||
@ -106,7 +115,7 @@ class MumbleBot:
|
||||
else:
|
||||
return
|
||||
|
||||
print(command + ' - ' + parameter + ' by ' + self.mumble.users[text.actor]['name'])
|
||||
logging.info(command + ' - ' + parameter + ' by ' + self.mumble.users[text.actor]['name'])
|
||||
|
||||
if command == self.config.get('command', 'play_file') and parameter:
|
||||
path = self.config.get('bot', 'music_folder') + parameter
|
||||
@ -121,6 +130,8 @@ class MumbleBot:
|
||||
var.playlist.append(["url", parameter])
|
||||
|
||||
elif command == self.config.get('command', 'play_radio') and parameter:
|
||||
if self.config.has_option('radio', parameter):
|
||||
parameter = self.config.get('radio', parameter)
|
||||
var.playlist.append(["radio", parameter])
|
||||
|
||||
elif command == self.config.get('command', 'help'):
|
||||
@ -162,9 +173,14 @@ class MumbleBot:
|
||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'not_playing'))
|
||||
|
||||
elif command == self.config.get('command', 'next'):
|
||||
var.current_music = var.playlist[0]
|
||||
var.playlist.pop(0)
|
||||
self.launch_next()
|
||||
if var.playlist:
|
||||
var.current_music = var.playlist[0]
|
||||
var.playlist.pop(0)
|
||||
self.launch_next()
|
||||
else:
|
||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'empty_playlist'))
|
||||
self.stop()
|
||||
|
||||
else:
|
||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'bad_command'))
|
||||
|
||||
@ -180,9 +196,9 @@ class MumbleBot:
|
||||
path = ""
|
||||
title = ""
|
||||
if var.current_music[0] == "url":
|
||||
regex = re.compile("<a href=\"(.*?)\"")
|
||||
m = regex.match(var.current_music[1])
|
||||
url = m.group(1)
|
||||
url = media.get_url(var.current_music[1])
|
||||
if not url:
|
||||
return
|
||||
path, title = self.download_music(url)
|
||||
var.current_music[1] = url
|
||||
|
||||
@ -191,9 +207,9 @@ class MumbleBot:
|
||||
title = var.current_music[1]
|
||||
|
||||
elif var.current_music[0] == "radio":
|
||||
regex = re.compile("<a href=\"(.*?)\"")
|
||||
m = regex.match(var.current_music[1])
|
||||
url = m.group(1)
|
||||
url = media.get_url(var.current_music[1])
|
||||
if not url:
|
||||
return
|
||||
var.current_music[1] = url
|
||||
path = url
|
||||
title = media.get_radio_server_description(url)
|
||||
@ -249,10 +265,13 @@ class MumbleBot:
|
||||
else:
|
||||
time.sleep(0.1)
|
||||
|
||||
if (self.thread is None or not raw_music) and len(var.playlist) != 0:
|
||||
var.current_music = var.playlist[0]
|
||||
var.playlist.pop(0)
|
||||
self.launch_next()
|
||||
if self.thread is None or not raw_music:
|
||||
if len(var.playlist) != 0:
|
||||
var.current_music = var.playlist[0]
|
||||
var.playlist.pop(0)
|
||||
self.launch_next()
|
||||
elif len(var.playlist) == 0 and var.current_music:
|
||||
var.current_music = None
|
||||
|
||||
while self.mumble.sound_output.get_buffer_size() > 0:
|
||||
time.sleep(0.01)
|
||||
|
Reference in New Issue
Block a user