Skip to content

Commit

Permalink
Updated scripts to use PGUI configs
Browse files Browse the repository at this point in the history
- Updated all built-in plugins to use the PGUI configs unless overriden
- Added version information to !about command outputs
- Left justified some PGUI elements
- Removed some unused code
- Updated privileges python file to use python3.6+ string formatting
  • Loading branch information
Jason committed Apr 18, 2019
1 parent f5f914a commit 5b9d608
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 63 deletions.
10 changes: 5 additions & 5 deletions JJMumbleBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ def process_core_commands(self, command, text):
elif command == "aliases":
if not pv.plugin_privilege_checker(self.mumble, text, command, self.priv_path):
return
cur_text = "<font color='red'>Registered Aliases:</font>"
cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Registered Aliases:</font>"
for i, alias in enumerate(aliases.aliases):
cur_text += f"<br><font color='cyan'>[{alias}]</font><font color='yellow'> - [{BeautifulSoup(aliases.aliases[alias], 'html.parser').get_text()}]</font>"
cur_text += f"<br><font color={GM.cfg['PGUI_Settings']['IndexTextColor']}>[{alias}]</font> - [{BeautifulSoup(aliases.aliases[alias], 'html.parser').get_text()}]"
if i % 50 == 0 and i != 0:
# utils.echo(utils.get_my_channel(self.mumble), cur_text)
GM.gui.quick_gui(
Expand Down Expand Up @@ -478,17 +478,17 @@ def process_core_commands(self, command, text):
return
# utils.echo(utils.get_my_channel(self.mumble), utils.get_about())
GM.gui.quick_gui(
utils.get_about(),
f"{utils.get_about()}<br>{utils.get_bot_name()} is on version {utils.get_version()}",
text_type='header',
box_align='left')
return

elif command == "history":
if not pv.plugin_privilege_checker(self.mumble, text, command, self.priv_path):
return
cur_text = "<font color='red'>Command History:</font>"
cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Command History:</font>"
for i, item in enumerate(self.cmd_history.queue_storage):
cur_text += f"<br><font color='cyan'>[{i}]:</font> <font color='yellow'>{item}</font>"
cur_text += f"<br><font color={GM.cfg['PGUI_Settings']['IndexTextColor']}>[{i}]</font> - {item}"
if i % 50 == 0 and i != 0:
# utils.echo(utils.get_my_channel(self.mumble), cur_text)
GM.gui.quick_gui(
Expand Down
30 changes: 25 additions & 5 deletions pgui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from helpers.gui_helper import GUIHelper
from helpers.global_access import debug_print, reg_print
from helpers.global_access import GlobalMods as GM
import utils


Expand All @@ -13,22 +14,39 @@ def __init__(self, mumble):
self.mumble = mumble
debug_print("Pseudo-GUI initialized.")

def quick_gui(self, content, text_type="data", text_color='white', text_font='Calibri', text_align="center", bgcolor="black", border="0", box_align="center", row_align="center", cellspacing="5", channel=None, user=None):
def quick_gui(self, content, text_type="data", text_color=None, text_font='Calibri', text_align="center", bgcolor=None, border=None, box_align=None, row_align="center", cellpadding="5", cellspacing="5", channel=None, user=None):
if self.box_open:
return False
if channel is None:
channel = utils.get_my_channel(self.mumble)
self.open_box(bgcolor=bgcolor, border=border, align=box_align, cellspacing=cellspacing)
if bgcolor is None:
bgcolor = GM.cfg['PGUI_Settings']['CanvasBGColor']
print(bgcolor)
if box_align is None:
box_align = GM.cfg['PGUI_Settings']['CanvasAlignment']
if border is None:
border = GM.cfg['PGUI_Settings']['CanvasBorder']
if text_color is None:
text_color = GM.cfg['PGUI_Settings']['CanvasTextColor']

self.open_box(bgcolor=bgcolor, border=border, align=box_align, cellspacing=cellspacing, cellpadding=cellpadding)
content = self.make_content(content, text_type=text_type, text_color=text_color, text_font=text_font, text_align=text_align)
self.append_row(content, align=row_align)
self.close_box()
self.display_box(channel=channel, user=user)
self.clear_display()

def open_box(self, bgcolor="black", border="0", align="center", cellspacing="5"):
def open_box(self, bgcolor=None, border=None, align=None, cellspacing="5", cellpadding="5"):
if self.box_open:
return False
self.content = f'<table bgcolor="{bgcolor}" border="{border}" align="{align}" cellspacing="{cellspacing}">'
if bgcolor is None:
bgcolor = GM.cfg['PGUI_Settings']['CanvasBGColor']
if align is None:
align = GM.cfg['PGUI_Settings']['CanvasAlignment']
if border is None:
border = GM.cfg['PGUI_Settings']['CanvasBorder']

self.content = f'<table bgcolor="{bgcolor}" border="{border}" align="{align}" cellspacing="{cellspacing}" cellpadding="{cellpadding}">'
self.box_open = True
return True

Expand All @@ -51,9 +69,11 @@ def append_content(self, content):
self.content += content
return True

def make_content(self, text, text_type="data", text_color='white', text_font='Calibri', text_align="center"):
def make_content(self, text, text_type="data", text_color=None, text_font='Calibri', text_align="center"):
if not self.box_open:
return None
if text_color is None:
text_color = GM.cfg['PGUI_Settings']['CanvasTextColor']
new_content = GUIHelper.content(text, tt=text_type, tc=text_color, tf=text_font, ta=text_align)
return new_content

Expand Down
10 changes: 5 additions & 5 deletions plugins/bot_commands/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def process_command(self, mumble, text):
return
# utils.echo(utils.get_my_channel(mumble),
# f"{pv.get_all_privileges()}")
GM.gui.quick_gui(f"{pv.get_all_privileges()}", text_type='header', box_align='center')
GM.gui.quick_gui(f"{pv.get_all_privileges()}", text_type='header', box_align='left', text_align='left')
return

elif command == "setprivileges":
Expand Down Expand Up @@ -179,13 +179,13 @@ def process_command(self, mumble, text):
# utils.echo(utils.get_my_channel(mumble),
# "<br>User: {parameter} added to the blacklist.<br>Reason: {reason}")
GM.gui.quick_gui(f"User: {parameter} added to the blacklist.<br>Reason: {reason}", text_type='header',
box_align='left')
box_align='left', text_align='left')
GM.logger.info(f"<br>Blacklisted user: {parameter} <br>Reason: {reason}")
except IndexError:
utils.echo(utils.get_my_channel(mumble),
pv.get_blacklist())
# utils.echo(utils.get_my_channel(mumble),
# pv.get_blacklist())
GM.gui.quick_gui(pv.get_blacklist(), text_type='header',
box_align='center')
box_align='left', text_align='left')
return

elif command == "whitelist":
Expand Down
1 change: 0 additions & 1 deletion plugins/help/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Plugin(PluginBase):
<b>!images_help/!img_help</b>: Displays the images plugin help screen.<br>\
<b>!randomizer_help</b>: Displays the randomizer plugin help screen.<br>\
<b>!uptime_help</b> Displays the uptime plugin help screen.<br>"
plugin_prepend_text = "<br><font color='red'>Plugin Version: "
plugin_version = "1.8.0"
priv_path = "help/help_privileges.csv"
bot_plugins = {}
Expand Down
8 changes: 4 additions & 4 deletions plugins/images/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def process_command(self, mumble, text):
for file_item in os.listdir(utils.get_permanent_media_dir() + "images/"):
if file_item.endswith(".jpg"):
internal_list.append(
f"<br><font color='cyan'>[{file_counter}]:</font> <font color='yellow'>{file_item}</font>")
f"<br><font color={GM.cfg['PGUI_Settings']['IndexTextColor']}>[{file_counter}]</font> - {file_item}")
file_counter += 1

cur_text = "<font color='red'>Local Image Files</font>"
cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Image Files:</font>"
if len(internal_list) == 0:
cur_text += "<br>There are no local image files available."
GM.gui.quick_gui(cur_text, text_type='header', box_align='left', user=mumble.users[text.actor]['name'])
Expand Down Expand Up @@ -101,10 +101,10 @@ def process_command(self, mumble, text):
for file_item in os.listdir(utils.get_permanent_media_dir() + "images/"):
if file_item.endswith(".jpg"):
internal_list.append(
f"<br><font color='cyan'>[{file_counter}]:</font> <font color='yellow'>{file_item}</font>")
f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{file_counter}]</font> - {file_item}")
file_counter += 1

cur_text = "<font color='red'>Local Image Files</font>"
cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Image Files:</font>"
if len(internal_list) == 0:
cur_text += "<br>There are no local image files available."
GM.gui.quick_gui(cur_text, text_type='header', box_align='left')
Expand Down
10 changes: 5 additions & 5 deletions plugins/sound_board/sound_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def process_command(self, mumble, text):

for file_item in os.listdir(utils.get_permanent_media_dir()+"sound_board/"):
if file_item.endswith(".wav"):
internal_list.append(f"<br><font color='cyan'>[{file_counter}]:</font> <font color='yellow'>{file_item}</font>")
internal_list.append(f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{file_counter}]</font> - {file_item}")
file_counter += 1

cur_text = "<font color='red'>Local Sound Board Files</font>"
cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Sound Board Files:</font>"
if len(internal_list) == 0:
cur_text += "<br>There are no local sound board files available."
GM.gui.quick_gui(cur_text, text_type='header', box_align='left')
GM.gui.quick_gui(cur_text, text_type='header', box_align='left', user=mumble.users[text.actor]['name'])
GM.logger.info("Displayed a list of all local sound board files.")
return

Expand All @@ -97,10 +97,10 @@ def process_command(self, mumble, text):

for file_item in os.listdir(utils.get_permanent_media_dir()+"sound_board/"):
if file_item.endswith(".wav"):
internal_list.append(f"<br><font color='cyan'>[{file_counter}]:</font> <font color='yellow'>{file_item}</font>")
internal_list.append(f"<br><font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{file_counter}]</font> - {file_item}")
file_counter += 1

cur_text = "<br><font color='red'>Local Sound Board Files</font>"
cur_text = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Local Sound Board Files:</font>"
if len(internal_list) == 0:
cur_text += "<br>There are no local sound board files available."
GM.gui.quick_gui(cur_text, text_type='header', box_align='left')
Expand Down
4 changes: 2 additions & 2 deletions plugins/youtube/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ def get_vid_list(self, search):
return search_results_list

def get_choices(self, all_searches):
list_urls = "<font color='red'>Search Results:</font><br>"
list_urls = f"<font color='{GM.cfg['PGUI_Settings']['HeaderTextColor']}'>Search Results:</font><br>"
for i in range(10):
completed_url = "https://www.youtube.com" + all_searches[i]['href']
list_urls += f"<font color='yellow'>[{i}]:</font> <a href='{completed_url}'>[{all_searches[i]['title']}]</a><br>"
list_urls += f"<font color='{GM.cfg['PGUI_Settings']['IndexTextColor']}'>[{i}]</font> - <a href='{completed_url}'>[{all_searches[i]['title']}]</a><br>"
return list_urls

def clear_queue(self):
Expand Down
Loading

0 comments on commit 5b9d608

Please sign in to comment.