parent
ce497f0b40
commit
ef78b566af
@ -37,6 +37,12 @@ listening_addr = 127.0.0.1
|
|||||||
listening_port = 8181
|
listening_port = 8181
|
||||||
|
|
||||||
[command]
|
[command]
|
||||||
|
#This it the char (only on letter) the bot will recognize as a command
|
||||||
|
command_symbol = !
|
||||||
|
#this option split username, in case you use such kind of mumo plugins https://wiki.mumble.info/wiki/Mumo#Set_Status
|
||||||
|
split_username_at_space = False
|
||||||
|
|
||||||
|
|
||||||
play_file = file
|
play_file = file
|
||||||
play_url = url
|
play_url = url
|
||||||
play_radio = radio
|
play_radio = radio
|
||||||
@ -55,6 +61,14 @@ queue = queue
|
|||||||
repeat = repeat
|
repeat = repeat
|
||||||
update = update
|
update = update
|
||||||
|
|
||||||
|
user_ban = userban
|
||||||
|
user_unban = userunban
|
||||||
|
url_ban = urlban
|
||||||
|
url_unban = urlunban
|
||||||
|
|
||||||
|
#command to reload the ban list
|
||||||
|
reload = reload
|
||||||
|
|
||||||
[radio]
|
[radio]
|
||||||
ponyville = http://192.99.131.205:8000/stream.mp3
|
ponyville = http://192.99.131.205:8000/stream.mp3
|
||||||
luna = http://radio.ponyvillelive.com:8002/stream
|
luna = http://radio.ponyvillelive.com:8002/stream
|
||||||
@ -82,6 +96,8 @@ too_long = This music is too long, skipping !
|
|||||||
download_in_progress = Download of %s in progress
|
download_in_progress = Download of %s in progress
|
||||||
no_possible = it's not possible to do that
|
no_possible = it's not possible to do that
|
||||||
removing_item = Removing entry %s from queue
|
removing_item = Removing entry %s from queue
|
||||||
|
user_ban = You are ban, not allowed to do that !
|
||||||
|
url_ban = This url isn't allowed !
|
||||||
|
|
||||||
help = Command available:
|
help = Command available:
|
||||||
<br />!file [path]
|
<br />!file [path]
|
||||||
@ -90,12 +106,22 @@ help = Command available:
|
|||||||
<br />!radio [url] - url of a stream
|
<br />!radio [url] - url of a stream
|
||||||
<br />!list - display list of available tracks
|
<br />!list - display list of available tracks
|
||||||
<br />!queue - display items in queue
|
<br />!queue - display items in queue
|
||||||
|
<br />!np - display the current music
|
||||||
<br />!skip - jump to the next music of the playlist (of remove the X items if you add a number)
|
<br />!skip - jump to the next music of the playlist (of remove the X items if you add a number)
|
||||||
<br />!stop - stop and clear the playlist
|
<br />!stop - stop and clear the playlist
|
||||||
<br />!oust - stop + Go to default channel
|
<br />!oust - stop + Go to default channel
|
||||||
<br />!v - get or change the volume (in %)
|
<br />!v - get or change the volume (in %)
|
||||||
<br />!joinme - join your own channel
|
<br />!joinme - join your own channel
|
||||||
|
|
||||||
|
admin_help = Admin command:
|
||||||
|
<br />!kill (kill the bot)
|
||||||
|
<br />!update (update the bot)
|
||||||
|
<br />!userban [user] (ban a user)
|
||||||
|
<br />!userunban [user] (unban a user)
|
||||||
|
<br />!urlban [url] (ban an url)
|
||||||
|
<br />!urlunban [url] (unban an url)
|
||||||
|
<br />!reload (reload the ban config)
|
||||||
|
<br />
|
||||||
[debug]
|
[debug]
|
||||||
ffmpeg = False
|
ffmpeg = False
|
||||||
mumbleConnection = False
|
mumbleConnection = False
|
||||||
|
@ -16,6 +16,8 @@ def get_url_info(index=-1):
|
|||||||
var.playlist[index]['title'] = info['title']
|
var.playlist[index]['title'] = info['title']
|
||||||
except youtube_dl.utils.DownloadError:
|
except youtube_dl.utils.DownloadError:
|
||||||
pass
|
pass
|
||||||
|
except KeyError:
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
75
mumbleBot.py
75
mumbleBot.py
@ -32,6 +32,9 @@ class MumbleBot:
|
|||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
signal.signal(signal.SIGINT, self.ctrl_caught)
|
signal.signal(signal.SIGINT, self.ctrl_caught)
|
||||||
self.volume = var.config.getfloat('bot', 'volume')
|
self.volume = var.config.getfloat('bot', 'volume')
|
||||||
|
if db.has_option('bot', 'volume'):
|
||||||
|
self.volume = var.db.getfloat('bot', 'volume')
|
||||||
|
|
||||||
self.channel = args.channel
|
self.channel = args.channel
|
||||||
|
|
||||||
FORMAT = '%(asctime)s: %(message)s'
|
FORMAT = '%(asctime)s: %(message)s'
|
||||||
@ -77,11 +80,11 @@ class MumbleBot:
|
|||||||
password = var.config.get("server", "password")
|
password = var.config.get("server", "password")
|
||||||
|
|
||||||
if args.user:
|
if args.user:
|
||||||
username = args.user
|
self.username = args.user
|
||||||
else:
|
else:
|
||||||
username = var.config.get("bot", "username")
|
self.username = var.config.get("bot", "username")
|
||||||
|
|
||||||
self.mumble = pymumble.Mumble(host, user=username, port=port, password=password,
|
self.mumble = pymumble.Mumble(host, user=self.username, port=port, password=password,
|
||||||
debug=var.config.getboolean('debug', 'mumbleConnection'), certfile=args.certificate)
|
debug=var.config.getboolean('debug', 'mumbleConnection'), certfile=args.certificate)
|
||||||
self.mumble.callbacks.set_callback("text_received", self.message_received)
|
self.mumble.callbacks.set_callback("text_received", self.message_received)
|
||||||
|
|
||||||
@ -108,7 +111,9 @@ class MumbleBot:
|
|||||||
def message_received(self, text):
|
def message_received(self, text):
|
||||||
message = text.message.strip()
|
message = text.message.strip()
|
||||||
user = self.mumble.users[text.actor]['name']
|
user = self.mumble.users[text.actor]['name']
|
||||||
if message[0] == '!':
|
if var.config.getboolean('command', 'split_username_at_space'):
|
||||||
|
user = user.split()[0]
|
||||||
|
if message[0] == var.config.get('command', 'command_symbol'):
|
||||||
message = message[1:].split(' ', 1)
|
message = message[1:].split(' ', 1)
|
||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
command = message[0]
|
command = message[0]
|
||||||
@ -133,6 +138,53 @@ class MumbleBot:
|
|||||||
self.mumble.users[text.actor].send_message(var.config.get('strings', 'pm_not_allowed'))
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'pm_not_allowed'))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for i in var.db.items("user_ban"):
|
||||||
|
if user.lower() == i[0]:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'user_ban'))
|
||||||
|
return
|
||||||
|
|
||||||
|
if command == var.config.get('command', 'user_ban'):
|
||||||
|
if self.is_admin(user):
|
||||||
|
if parameter:
|
||||||
|
self.mumble.users[text.actor].send_message(util.user_ban(parameter))
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(util.get_user_ban())
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'not_admin'))
|
||||||
|
return
|
||||||
|
|
||||||
|
elif command == var.config.get('command', 'user_unban'):
|
||||||
|
if self.is_admin(user):
|
||||||
|
if parameter:
|
||||||
|
self.mumble.users[text.actor].send_message(util.user_unban(parameter))
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'not_admin'))
|
||||||
|
return
|
||||||
|
|
||||||
|
elif command == var.config.get('command', 'url_ban'):
|
||||||
|
if self.is_admin(user):
|
||||||
|
if parameter:
|
||||||
|
self.mumble.users[text.actor].send_message(util.url_ban(self.get_url_from_input(parameter)))
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(util.get_url_ban())
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'not_admin'))
|
||||||
|
return
|
||||||
|
|
||||||
|
elif command == var.config.get('command', 'url_unban'):
|
||||||
|
if self.is_admin(user):
|
||||||
|
if parameter:
|
||||||
|
self.mumble.users[text.actor].send_message(util.url_unban(self.get_url_from_input(parameter)))
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'not_admin'))
|
||||||
|
return
|
||||||
|
|
||||||
|
if parameter:
|
||||||
|
for i in var.db.items("url_ban"):
|
||||||
|
if self.get_url_from_input(parameter.lower()) == i[0]:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'url_ban'))
|
||||||
|
return
|
||||||
|
|
||||||
if command == var.config.get('command', 'play_file') and parameter:
|
if command == var.config.get('command', 'play_file') and parameter:
|
||||||
music_folder = var.config.get('bot', 'music_folder')
|
music_folder = var.config.get('bot', 'music_folder')
|
||||||
# sanitize "../" and so on
|
# sanitize "../" and so on
|
||||||
@ -163,7 +215,6 @@ class MumbleBot:
|
|||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
|
|
||||||
elif command == var.config.get('command', 'play_url') and parameter:
|
elif command == var.config.get('command', 'play_url') and parameter:
|
||||||
|
|
||||||
music = {'type': 'url',
|
music = {'type': 'url',
|
||||||
'url': self.get_url_from_input(parameter),
|
'url': self.get_url_from_input(parameter),
|
||||||
'user': user,
|
'user': user,
|
||||||
@ -175,6 +226,12 @@ class MumbleBot:
|
|||||||
var.playlist.pop()
|
var.playlist.pop()
|
||||||
self.send_msg(var.config.get('strings', 'too_long'), text)
|
self.send_msg(var.config.get('strings', 'too_long'), text)
|
||||||
else:
|
else:
|
||||||
|
for i in var.db.options("url_ban"):
|
||||||
|
print(i, ' -> ', {var.playlist[-1]["url"]})
|
||||||
|
if var.playlist[-1]['url'] == i:
|
||||||
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'url_ban'))
|
||||||
|
var.playlist.pop()
|
||||||
|
return
|
||||||
var.playlist[-1]['ready'] = "no"
|
var.playlist[-1]['ready'] = "no"
|
||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
else:
|
else:
|
||||||
@ -313,7 +370,7 @@ class MumbleBot:
|
|||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
|
|
||||||
elif command == var.config.get('command', 'repeat'):
|
elif command == var.config.get('command', 'repeat'):
|
||||||
var.playlist.append([var.playlist[0]["type"], var.playlist[0]["path"], var.playlist[0]["user"]])
|
var.playlist.append(var.playlist[0])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.mumble.users[text.actor].send_message(var.config.get('strings', 'bad_command'))
|
self.mumble.users[text.actor].send_message(var.config.get('strings', 'bad_command'))
|
||||||
@ -549,10 +606,10 @@ if __name__ == '__main__':
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
var.dbfile = args.db
|
var.dbfile = args.db
|
||||||
config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
|
config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
|
||||||
parsed_configs = config.read(['configuration.default.ini', args.config, var.dbfile], encoding='latin-1')
|
parsed_configs = config.read(['configuration.default.ini', args.config], encoding='latin-1')
|
||||||
|
|
||||||
db = configparser.ConfigParser(interpolation=None, allow_no_value=True)
|
db = configparser.ConfigParser(interpolation=None, allow_no_value=True, delimiters='²')
|
||||||
db.read([var.dbfile], encoding='latin-1')
|
db.read(var.dbfile, encoding='latin-1')
|
||||||
|
|
||||||
if len(parsed_configs) == 0:
|
if len(parsed_configs) == 0:
|
||||||
logging.error('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr)
|
logging.error('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr)
|
||||||
|
42
util.py
42
util.py
@ -71,6 +71,48 @@ def write_db():
|
|||||||
var.db.write(f)
|
var.db.write(f)
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_ban():
|
||||||
|
res = "List of ban hash"
|
||||||
|
for i in var.db.items("user_ban"):
|
||||||
|
res += "<br/>" + i[0]
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def user_ban(user):
|
||||||
|
var.db.set("user_ban", user, None)
|
||||||
|
res = "User " + user + " banned"
|
||||||
|
write_db()
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def user_unban(user):
|
||||||
|
var.db.remove_option("user_ban", user)
|
||||||
|
res = "Done"
|
||||||
|
write_db()
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def get_url_ban():
|
||||||
|
res = "List of ban hash"
|
||||||
|
for i in var.db.items("url_ban"):
|
||||||
|
res += "<br/>" + i[0]
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def url_ban(url):
|
||||||
|
var.db.set("url_ban", url, None)
|
||||||
|
res = "url " + url + " banned"
|
||||||
|
write_db()
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def url_unban(url):
|
||||||
|
var.db.remove_option("url_ban", url)
|
||||||
|
res = "Done"
|
||||||
|
write_db()
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
class Dir(object):
|
class Dir(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.name = os.path.basename(path.strip('/'))
|
self.name = os.path.basename(path.strip('/'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user