Skip to content

Commit

Permalink
Merge pull request #249 from DuckBoss/v4.0.0-testing
Browse files Browse the repository at this point in the history
Updates for v4.0.0
  • Loading branch information
DuckBoss authored Jul 29, 2020
2 parents c33e82d + 6388106 commit dc71e99
Show file tree
Hide file tree
Showing 23 changed files with 544 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: jasonjerome
ko_fi:
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
Expand Down
5 changes: 2 additions & 3 deletions JJMumbleBot/cfg/templates/config_template.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[Connection Settings]
; Please don't surround any values in quotations!
ServerIP = SERVER_IP
; Enter your bot username here, If the bot is registered with a certificate, the name must match the name in the certificate.
UserID = USERNAME
ServerPassword = PASSWORD
ServerPort = PORT_NUMBER
; Enter the file path to your certificate. If your server doesn't require a certificate, leave this blank.
UserCertification = CERT_FILE_PATH
; Auto-Reconnect to the server if connection is lost.
AutoReconnect = False
Expand Down
19 changes: 9 additions & 10 deletions JJMumbleBot/core/bot_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class BotService:
def __init__(self):
def __init__(self, serv_ip, serv_port, serv_pass):
# Initialize bot services.
global_settings.bot_service = self
# Initialize user settings.
Expand Down Expand Up @@ -57,12 +57,12 @@ def __init__(self):
dir_utils.make_directory(global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR])
dir_utils.make_directory(f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/images')
dir_utils.make_directory(f'{global_settings.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]}/internal/audio')
log(INFO, "Initialized Temporary Directories.", origin=L_STARTUP)
rprint("Initialized Temporary Directories.", origin=L_STARTUP)
log(INFO, "######### Initialized Temporary Directories #########", origin=L_STARTUP)
rprint("######### Initialized Temporary Directories #########", origin=L_STARTUP)
# Initialize PGUI system.
global_settings.gui_service = PseudoGUI()
log(INFO, "Initialized PGUI.", origin=L_STARTUP)
rprint("Initialized PGUI.", origin=L_STARTUP)
log(INFO, "######### Initialized PGUI #########", origin=L_STARTUP)
rprint("######### Initialized PGUI #########", origin=L_STARTUP)
# Initialize VLC interface.
global_settings.vlc_interface = VLCInterface()
# Initialize plugins.
Expand All @@ -73,12 +73,10 @@ def __init__(self):
rprint("Initialized plugins with safe mode.", origin=L_STARTUP)
else:
BotServiceHelper.initialize_plugins()
log(INFO, "Initialized all plugins.", origin=L_STARTUP)
rprint("Initialized all plugins.", origin=L_STARTUP)
log(INFO, "######### Initializing Mumble Client #########", origin=L_STARTUP)
rprint("######### Initializing Mumble Client #########", origin=L_STARTUP)
# Retrieve mumble client data from configs.
mumble_login_data = BotServiceHelper.retrieve_mumble_data()
mumble_login_data = BotServiceHelper.retrieve_mumble_data(serv_ip, serv_port, serv_pass)
BotService.initialize_mumble(mumble_login_data)
log(INFO, "######### Initialized Mumble Client #########", origin=L_STARTUP)
rprint("######### Initialized Mumble Client #########", origin=L_STARTUP)
Expand All @@ -96,15 +94,16 @@ def __init__(self):
@staticmethod
def initialize_mumble(md: MumbleData):
global_settings.mumble_inst = pymumble.Mumble(md.ip_address, port=md.port, user=md.user_id, reconnect=md.auto_reconnect,
password=md.password, certfile=md.certificate, stereo=md.stereo)
password=md.password, certfile=md.certificate, stereo=md.stereo)
global_settings.mumble_inst.callbacks.set_callback('text_received', BotService.message_received)
global_settings.mumble_inst.callbacks.set_callback('sound_received', BotService.sound_received)
global_settings.mumble_inst.callbacks.set_callback('connected', BotService.on_connected)
global_settings.mumble_inst.set_codec_profile('audio')
global_settings.mumble_inst.set_receive_sound(True)
global_settings.mumble_inst.start()
global_settings.mumble_inst.is_ready()
if global_settings.cfg.getboolean(C_CONNECTION_SETTINGS, P_SELF_REGISTER):

if global_settings.cfg.getboolean(C_CONNECTION_SETTINGS, P_SELF_REGISTER, fallback=False):
global_settings.mumble_inst.users.myself.register()
global_settings.mumble_inst.users.myself.comment(
f'{runtime_utils.get_comment()}<br>[{META_NAME}({META_VERSION})] - {runtime_utils.get_bot_name()}<br>{runtime_utils.get_about()}')
Expand Down
8 changes: 4 additions & 4 deletions JJMumbleBot/lib/helpers/bot_service_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

class BotServiceHelper:
@staticmethod
def retrieve_mumble_data():
server_ip: str = global_settings.cfg[C_CONNECTION_SETTINGS][P_SERVER_IP]
server_pass: str = global_settings.cfg[C_CONNECTION_SETTINGS][P_SERVER_PASS]
server_port: int = int(global_settings.cfg[C_CONNECTION_SETTINGS][P_SERVER_PORT])
def retrieve_mumble_data(serv_ip, serv_port, serv_pass):
server_ip: str = serv_ip
server_pass: str = serv_pass
server_port: int = serv_port
user_id: str = global_settings.cfg[C_CONNECTION_SETTINGS][P_USER_ID]
user_cert: str = global_settings.cfg[C_CONNECTION_SETTINGS][P_USER_CERT]
use_stereo: bool = global_settings.cfg.getboolean(C_MEDIA_SETTINGS, P_MEDIA_VLC_STEREO, fallback=True)
Expand Down
8 changes: 0 additions & 8 deletions JJMumbleBot/lib/monitor_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import timedelta
import psutil
import platform
from JJMumbleBot.settings import global_settings
from JJMumbleBot.lib.utils.runtime_utils import get_all_channels
Expand Down Expand Up @@ -70,13 +69,6 @@ def get_all_online():
return online_user_info


def get_hardware_info():
return {
"cpu_usage": f'{psutil.cpu_percent()}%',
"mem_usage": f'{psutil.virtual_memory().percent}%'
}


def get_last_command_output():
return {
"last_cmd_type": f'{global_settings.last_command_type}',
Expand Down
3 changes: 0 additions & 3 deletions JJMumbleBot/lib/resources/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
C_LOGGING = 'Logging'
# PROGRAM CONFIG PARAMETER STRINGS
# Connection Settings
P_SERVER_IP = 'ServerIP'
P_SERVER_PASS = 'ServerPassword'
P_SERVER_PORT = 'ServerPort'
P_USER_ID = 'UserID'
P_USER_CERT = 'UserCertification'
P_SERVER_RECONNECT = 'AutoReconnect'
Expand Down
28 changes: 15 additions & 13 deletions JJMumbleBot/lib/utils/runtime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,13 @@ def refresh_plugins():

def exit_bot():
from JJMumbleBot.lib.utils import dir_utils
global_settings.gui_service.quick_gui(
f"{get_bot_name()} is being shutdown.",
text_type='header',
box_align='left',
ignore_whisper=True,
)
if global_settings.mumble_inst:
global_settings.gui_service.quick_gui(
f"{get_bot_name()} is being shutdown.",
text_type='header',
box_align='left',
ignore_whisper=True,
)
for plugin in global_settings.bot_plugins.values():
plugin.quit()
if global_settings.flask_server:
Expand All @@ -368,13 +369,14 @@ def exit_bot():

def exit_bot_error(error_code: ExitCodes):
from JJMumbleBot.lib.utils import dir_utils
global_settings.gui_service.quick_gui(
f"{get_bot_name()} has encountered an error and is being shutdown.<br>Please check the bot logs/console."
f"<br>Exit Code: {error_code.value}",
text_type='header',
box_align='center',
ignore_whisper=True,
)
if global_settings.mumble_inst:
global_settings.gui_service.quick_gui(
f"{get_bot_name()} has encountered an error and is being shutdown.<br>Please check the bot logs/console."
f"<br>Exit Code: {error_code.value}",
text_type='header',
box_align='center',
ignore_whisper=True,
)
try:
for plugin in global_settings.bot_plugins.values():
plugin.quit()
Expand Down
10 changes: 5 additions & 5 deletions JJMumbleBot/lib/vlc/vlc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@


class TrackStatus(Enum):
PLAYING = 'playing'
PAUSED = 'paused'
STOPPED = 'stopped'
PLAYING = 'Playing'
PAUSED = 'Paused'
STOPPED = 'Stopped'


class TrackType(Enum):
FILE = 'file'
STREAM = 'stream'
FILE = 'File'
STREAM = 'Stream'


class TrackInfo:
Expand Down
6 changes: 3 additions & 3 deletions JJMumbleBot/plugins/core/bot_commands/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def cmd_showblacklist(self, data):

def cmd_blacklistuser(self, data):
try:
all_data = data.message.strip().split()
all_data = data.message.strip().split(' ', 2)
reason = "No reason provided."
if len(all_data) > 2:
reason = all_data[2]
Expand All @@ -197,7 +197,7 @@ def cmd_blacklistuser(self, data):

def cmd_whitelistuser(self, data):
try:
all_data = data.message.strip().split()
all_data = data.message.strip().split(' ', 1)
result = privileges.remove_from_blacklist(all_data[1])
if result:
gs.gui_service.quick_gui(f"User: {all_data[1]} removed from the blacklist.",
Expand All @@ -208,7 +208,7 @@ def cmd_whitelistuser(self, data):
)
log(INFO, f"User: {all_data[1]} removed from the blacklist.", origin=L_USER_PRIV)
except IndexError:
gs.gui_service.quick_gui("Command format: !whitelist username",
gs.gui_service.quick_gui(f"Incorrect format! Format: {rutils.get_command_token()}whitelistuser 'username'",
text_type='header',
box_align='left',
user=gs.mumble_inst.users[data.actor]['name'],
Expand Down
4 changes: 2 additions & 2 deletions JJMumbleBot/plugins/core/bot_commands/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<b>!setprivileges 'username' 'level'</b>: Sets a user's privilege level.<br>
<b>!addprivileges 'username' 'level'</b>: Adds a new user to the user privilege list.<br>
<b>!showblacklist</b>: Displays the current list of users in the blacklist.<br>
<b>!blacklist 'username'</b>: Blacklists specific users from using certain plugin commands.<br>
<b>!whitelist 'username'</b>: Removes an existing user from the blacklist.
<b>!blacklistuser 'username'</b>: Blacklists specific users from using certain plugin commands.<br>
<b>!whitelistuser 'username'</b>: Removes an existing user from the blacklist.
10 changes: 5 additions & 5 deletions JJMumbleBot/plugins/core/core_commands/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<b>!exit/!quit</b>: Initializes the bot exit procedure.<br>
<b>!help</b>: Displays a list of the help commands for all the available plugins.<br>
<b>!help 'plugin_name'</b>: Displays all the commands available for the given plugin.<br>
<b>!comment 'comment_text'</b>: Sets the bot's user comment with the given text.<br>
<b>!setcomment 'comment_text'</b>: Sets the bot's user comment with the given text.<br>
<b>!resetcomment</b>: Resets the bot's user comment to the default text.<br>
<b>!pgui_stress_test</b>: Conducts a stress test of the PGUI system in the channel chat. Uses a default of 5 lines.
<b>!pgui_stress_test 'number of lines'</b>: Conducts a stress test of the PGUI system in the channel chat. Optionally set the number of lines to control the size of the test.
<b>!pguistresstest</b>: Conducts a stress test of the PGUI system in the channel chat. Uses a default of 5 lines.
<b>!pguistresstest 'number of lines'</b>: Conducts a stress test of the PGUI system in the channel chat. Optionally set the number of lines to control the size of the test.
<b>!version</b>: Displays the bot version.<br>
<b>!refresh</b>: Refreshes all plugins.<br>
<b>!restartplugins</b>: Quits and restarts all active plugins.<br>
<b>!reboot/!restart</b>: Completely stops the bot and restarts it.<br>
<b>!safereboot/!saferestart</b>: Completely stops the bot and restarts it.<br>
<b>!about</b>: Displays the bots about screen.<br>
<b>!alias 'alias_name' 'command'|'command'|...</b>: Registers an alias for single/multi-commands.<br>
<b>!setalias 'alias_name' 'command'|'command'|...</b>: Registers an alias for single/multi-commands.<br>
<b>!removealias 'alias_name'</b>: Removes a registered alias by the given name.<br>
<b>!clearaliases</b>: Removes all registered aliases.<br>
<b>!aliases</b>: Displays a list of registered aliases.<br>
Expand Down
7 changes: 4 additions & 3 deletions JJMumbleBot/tests/dummy_config.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[Connection Settings]
; Please don't surround any values in quotations!
ServerIP = 127.0.0.1
UserID = TravisCIClient
ServerPassword = test
ServerPort = 64738
UserCertification = test_cert
; The default channel the bot joins when it connects to the server
DefaultChannel = Root
Expand Down Expand Up @@ -45,6 +42,10 @@ VLCDuckingThreshold: 2500.0
VLCDuckingDelay: 1.0
; The default maximum queue length for the audio interface (default=50)
VLCMaxQueueLength = 50
; Optional Proxy URL - If you want to use a proxy server to use the youtube-dl library, fill this out.
YoutubeDLProxyURL = YOUTUBE_DL_PROXY_URL
; Optionally use a cookies.txt file for the youtube-dl library (useful to deal with rate limits).
YoutubeDLCookieFile = YOUTUBE_DL_COOKIE_PATH
; Temporary images directory to store youtube thumbnails and other images content. This directory is cleared when the bot exits
TemporaryMediaDirectory = TEMP_MEDIA_DIR_PATH
; Permanent media directory to store sound board clips, and other media that won't be deleted when the bot exits
Expand Down
20 changes: 8 additions & 12 deletions JJMumbleBot/tests/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,10 @@ def test_version(self):
assert bot_version == META_VERSION

# Connection Config Tests
def test_server_ip(self):
server_ip = self.cfg[C_CONNECTION_SETTINGS][P_SERVER_IP]
assert server_ip == "SERVER_IP"

def test_user_id(self):
user_id = self.cfg[C_CONNECTION_SETTINGS][P_USER_ID]
assert user_id == "USERNAME"

def test_server_pass(self):
server_pass = self.cfg[C_CONNECTION_SETTINGS][P_SERVER_PASS]
assert server_pass == "PASSWORD"

def test_server_port(self):
server_port = self.cfg[C_CONNECTION_SETTINGS][P_SERVER_PORT]
assert server_port == "PORT_NUMBER"

def test_user_cert(self):
user_cert = self.cfg[C_CONNECTION_SETTINGS][P_USER_CERT]
assert user_cert == "CERT_FILE_PATH"
Expand Down Expand Up @@ -112,6 +100,14 @@ def test_vlc_max_queue_length(self):
vlc_max_queue_length = int(self.cfg[C_MEDIA_SETTINGS][P_MEDIA_VLC_QUEUE_LEN])
assert vlc_max_queue_length == 50

def test_youtube_dl_proxy(self):
youtube_dl_proxy = self.cfg[C_MEDIA_SETTINGS][P_MEDIA_PROXY_URL]
assert youtube_dl_proxy == ""

def test_youtube_dl_cookie(self):
youtube_dl_cookie = self.cfg[C_MEDIA_SETTINGS][P_MEDIA_COOKIE_FILE]
assert youtube_dl_cookie == ""

def test_temp_media_directory(self):
temp_media_directory = self.cfg[C_MEDIA_SETTINGS][P_TEMP_MED_DIR]
assert temp_media_directory == "TEMP_MEDIA_DIR_PATH"
Expand Down
2 changes: 1 addition & 1 deletion JJMumbleBot/tests/test_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def setup_method(self):
# Initialize configs.
global_settings.cfg = configparser.ConfigParser()
global_settings.cfg.read(f"{get_main_dir()}/tests/dummy_config.ini")
self.md = BotServiceHelper.retrieve_mumble_data()
self.md = BotServiceHelper.retrieve_mumble_data('127.0.0.1', 64738, 'test')

def test_connectivity(self):
mumble_inst = pymumble.Mumble(self.md.ip_address, port=self.md.port, user=self.md.user_id,
Expand Down
5 changes: 4 additions & 1 deletion JJMumbleBot/web/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ function setChannelInformation() {
var channel_list_fig = document.getElementById("channelsList");
channel_list_fig.innerHTML = "";
for (var chan_key of Object.keys(data_storage["channels"])) {
var channel_name = document.createElement("figcaption");
var channel_name = document.createElement("ul");
channel_name.classList.add("list-group");
channel_name.classList.add("list-group-flush");
channel_name.innerHTML = data_storage["channels"][parseInt(chan_key)]["name"];
channel_list_fig.appendChild(channel_name);

var channel_list_ul = document.createElement("ul");
channel_list_fig.appendChild(channel_list_ul)
channel_list_ul.classList.add("list-group");
channel_list_ul.classList.add("list-group-flush");
for (var user_key of Object.keys(data_storage["users"][parseInt(chan_key)])) {
Expand Down
3 changes: 0 additions & 3 deletions JJMumbleBot/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@
fetch('http://{{ server_ip }}:{{ server_port }}/system')
.then(response => response.json())
.then(json => $.extend(data_storage, json));
fetch('http://{{ server_ip }}:{{ server_port }}/hardware')
.then(response => response.json())
.then(json => $.extend(data_storage, json));

$('form').on('submit', function(event) {
$.ajax({
Expand Down
7 changes: 0 additions & 7 deletions JJMumbleBot/web/web_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ async def send_message(websocket, path):
web_tick_rate = float(global_settings.cfg[C_WEB_SETTINGS][P_WEB_TICK_RATE])
try:
while True:
# web_data = monitor_service.get_hardware_info()
# web_data.update(monitor_service.get_system_info())
web_data = {"cur_time": str(datetime.now()).split('.')[0]}
web_data.update({"bot_uptime": f'{check_up_time()}'})
web_data.update(monitor_service.get_last_command_output())
Expand Down Expand Up @@ -140,11 +138,6 @@ def get_system_info():
return json.dumps(monitor_service.get_system_info())


@web_app.route("/hardware", methods=['GET'])
def get_hardware_info():
return json.dumps(monitor_service.get_hardware_info())


@web_app.route("/", methods=['GET', 'POST'])
def main():
return render_template(
Expand Down
Loading

0 comments on commit dc71e99

Please sign in to comment.