Skip to content

Commit

Permalink
Merge pull request #94 from DuckBoss/development
Browse files Browse the repository at this point in the history
Updates for v2.2.0 - Whisper Plugin
  • Loading branch information
Jason (제이슨) authored May 1, 2019
2 parents 701c5de + f89ac1b commit 8c061e8
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 218 deletions.
208 changes: 0 additions & 208 deletions plugins/bot_commands/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ class Plugin(PluginBase):
<b>!blacklist</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.<br>\
<b>!setwhisperuser 'username'</b>: Sets the whisper target to the given user<br>\
<b>!setwhisperusers 'username1,username2,...'</b>: Sets the whisper target to multiple users.<br>\
<b>!addwhisperuser 'username'</b>: Adds the user to the whisper targets.<br>\
<b>!setwhisperme</b>: Sets the whisper target to the command sender.<br>\
<b>!setwhisperchannel 'channelname'</b>: Sets the whisper target to the given channel.<br>\
<b>!clearwhisper</b>: Clears any previously set whisper target.<br>\
<b>!removewhisperuser 'username'</b>: Removes a specific user from the whisper targets.<br>\
<b>!getwhisper</b>: Displays the current whisper target.<br>\
<b>!version</b>: Displays the bot version.<br>\
<b>!status</b>: Displays the bots current status.<br>\
<b>!refresh</b>: Refreshes all plugins.<br>\
Expand Down Expand Up @@ -197,206 +189,6 @@ def process_command(self, text):
return
return

elif command == "getwhisper":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
if GM.whisper_target is None:
GM.gui.quick_gui("There is no whisper target set", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
if GM.whisper_target["type"] == 0:
ch = GM.mumble.channels[GM.whisper_target['id']]['name']
GM.gui.quick_gui(f"Current whisper channel: {ch}", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
elif GM.whisper_target["type"] == 1:
us = ""
for user in GM.mumble.users:
if GM.mumble.users[user]['session'] == GM.whisper_target['id']:
us = GM.mumble.users[user]['name']
GM.gui.quick_gui(f"Current whisper user: {us}", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
elif GM.whisper_target["type"] == 2:
users = ""
counter = 0
for i, user in enumerate(GM.mumble.users):
if GM.mumble.users[user]['session'] in GM.whisper_target['id']:
users += f"<br>[{counter}] - {GM.mumble.users[user]['name']}"
counter += 1
GM.gui.quick_gui(f"Current whisper users: {users}", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return

elif command == "setwhisperuser":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
try:
parameter = message_parse[1]
if parameter == GM.cfg['Connection_Settings']['UserID']:
GM.logger.info("I can't set the whisper target to myself!")
GM.gui.quick_gui("I can't set the whisper target to myself!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
utils.set_whisper_user(parameter)

GM.gui.quick_gui(f"Set whisper to User: {parameter}", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
GM.logger.info(f"Set whisper to User: {parameter}.")
except IndexError:
GM.gui.quick_gui("Invalid whisper command!<br>Command format: !setwhisperuser username", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
return

elif command == "removewhisperuser":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
try:
username = message_parse[1]
if GM.whisper_target is not None:
if not isinstance(GM.whisper_target['id'], list):
GM.gui.quick_gui("<br>The current whisper mode is set to single user/channel."
"<br>You can only remove a user from a multi-user whisper mode."
"<br>Did you mean to use the 'clearwhisper' command?", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
else:
return

user_id = None
for user in GM.mumble.users:
if GM.mumble.users[user]['name'] == username:
user_id = GM.mumble.users[user]['session']
if user_id is not None:
if user_id in GM.whisper_target['id']:
GM.whisper_target['id'].remove(user_id)
else:
GM.gui.quick_gui(f"Could not find user: {username} in the whisper targets!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
else:
GM.gui.quick_gui(f"Could not find user: {username} in the whisper targets!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
if len(GM.whisper_target['id']) < 1:
utils.clear_whisper()
else:
utils.set_whisper_multi_user(GM.whisper_target['id'])

GM.gui.quick_gui(f"Removed user: {username} from the whisper targets!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
GM.logger.info(f"Removed user: {username} from the whisper targets!")
except IndexError:
GM.gui.quick_gui("Invalid whisper command!<br>Command format: !removewhisperuser username", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
return

elif command == "addwhisperuser":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
try:
username = message_parse[1]
if username == GM.cfg['Connection_Settings']['UserID']:
GM.logger.info("I can't add myself to the whisper targets!")
GM.gui.quick_gui("I can't add myself to the whisper targets!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
if GM.whisper_target is not None:
if not isinstance(GM.whisper_target['id'], list):
GM.gui.quick_gui("<br>The current whisper mode is set to single user.<br>Use the 'setwhisperusers' command for multi-user whispers.", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
else:
return
for user in GM.mumble.users:
if GM.mumble.users[user]['name'] == username:
if GM.mumble.users[user]['session'] in GM.whisper_target['id']:
GM.gui.quick_gui(
"<br>This user is already one of the whisper targets!",
text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return

GM.whisper_target['id'].append(username)
utils.set_whisper_multi_user(GM.whisper_target['id'])

GM.gui.quick_gui(f"Added new user: {username} to the whisper targets!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
GM.logger.info(f"Added new user: {username} to the whisper targets!")
except IndexError:
GM.gui.quick_gui("Invalid whisper command!<br>Command format: !addwhisperuser username", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
return

elif command == "setwhisperusers":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
try:
parameter = message_parse[1]

users_list = [user.strip() for user in parameter.split(',') if not user.strip() == GM.cfg['Connection_Settings']['UserID']]
if len(users_list) < 2:
GM.gui.quick_gui("Use the 'setwhisperuser' command for a single user!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return

utils.set_whisper_multi_user(users_list)

GM.gui.quick_gui(f"Added whisper to multiple users!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
GM.logger.info(f"Added whisper to multiple users!")
except IndexError:
GM.gui.quick_gui("Invalid whisper command!<br>Command format: !setwhisperusers username0,username1,...", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
return

elif command == "setwhisperme":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
parameter = GM.mumble.users[text.actor]['name']
if parameter == GM.cfg['Connection_Settings']['UserID']:
GM.logger.info("I can't set the whisper target to myself!")
return

utils.set_whisper_user(parameter)

GM.gui.quick_gui(f"Set whisper to user: {parameter}", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
GM.logger.info(f"Set whisper to user: {parameter}.")
return

elif command == "setwhisperchannel":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
try:
parameter = message_parse[1]
utils.set_whisper_channel(parameter)

GM.gui.quick_gui(f"Set whisper to channel: {parameter}", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
GM.logger.info(f"Set whisper to channel: {parameter}.")
except IndexError:
GM.gui.quick_gui("Command format: !setwhisperchannel channel_name", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
return

elif command == "clearwhisper":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
utils.clear_whisper()
if GM.whisper_target is None:
GM.gui.quick_gui(f"Cleared current whisper", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return
GM.gui.quick_gui("Unable to remove current whisper!", text_type='header',
box_align='left', user=GM.mumble.users[text.actor]['name'], ignore_whisper=True)
return

def plugin_test(self):
debug_print("Bot_Commands Plugin self-test callback.")

Expand Down
8 changes: 0 additions & 8 deletions plugins/bot_commands/bot_commands_privileges.csv
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,3 @@ sleep,2
history,2
reboot,4
uptime,1
setwhisperuser,4
setwhisperchannel,4
clearwhisper,4
setwhisperme,4
getwhisper,4
setwhisperusers,4
addwhisperuser,4
removewhisperuser,4
25 changes: 24 additions & 1 deletion plugins/help/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class Plugin(PluginBase):
help_data = "All commands can be run by typing it in the chat or privately messaging JJMumbleBot.<br>\
<b>!help</b>: Displays this general help screen.<br>\
<b>!bot_help</b>: Displays the bot_commands plugin help screen.<br>\
<b>!whisper_help</b>: Displays the whisper plugin help screen.<br>\
<b>!youtube_help/!yt_help</b>: Displays the youtube plugin help screen.<br>\
<b>!sound_board_help/!sb_help</b>: Displays the sound_board plugin help screen.<br>\
<b>!images_help/!img_help</b>: Displays the images plugin help screen.<br>\
<b>!randomizer_help</b>: Displays the randomizer plugin help screen.<br>"
plugin_version = "2.0.0"
plugin_version = "2.2.0"
priv_path = "help/help_privileges.csv"
bot_plugins = {}

Expand Down Expand Up @@ -72,6 +73,28 @@ def process_command(self, text):
GM.logger.info("Displayed bot commands plugin help screen in the channel.")
return

elif command == "whisper_help":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
GM.gui.open_box()
all_help_lines = [msg.strip() for msg in self.bot_plugins.get("whisper").help().split('<br>')]
content = GM.gui.make_content(f'<font color="red">#####</font> '
f'{GUIHelper.bold("Whisper Plugin Help")} '
f'<font color="red">#####</font>')
GM.gui.append_row(content)
content = GM.gui.make_content(f'Plugin Version: {self.bot_plugins.get("whisper").get_plugin_version()}<br>', text_color='cyan')
GM.gui.append_row(content)

for i, item in enumerate(all_help_lines):
content = GM.gui.make_content(f'{item}', 'header', text_color='yellow', text_align="left")
GM.gui.append_row(content)
GM.gui.close_box()
GM.gui.display_box(channel=utils.get_my_channel())

reg_print("Displayed whisper plugin help screen in the channel.")
GM.logger.info("Displayed whisper plugin help screen in the channel.")
return

elif command == "sound_board_help":
if not pv.plugin_privilege_checker(text, command, self.priv_path):
return
Expand Down
Loading

0 comments on commit 8c061e8

Please sign in to comment.