1- from base_plugin import SimpleCommandPlugin
1+ from base_plugin import SimpleCommandPlugin , BasePlugin
22from core_plugins .player_manager import permissions , UserLevels
3+ from packets import chat_sent
34from utility_functions import give_item_to_player
45
56
@@ -9,7 +10,7 @@ class UserCommandPlugin(SimpleCommandPlugin):
910 """
1011 name = "user_management_commands"
1112 depends = ['command_dispatcher' , 'player_manager' ]
12- commands = ["who" , "whois" , "promote" , "kick" , "ban" , "give_item" , "planet" ]
13+ commands = ["who" , "whois" , "promote" , "kick" , "ban" , "give_item" , "planet" , "mute" , "unmute" ]
1314 auto_activate = True
1415
1516 def activate (self ):
@@ -190,3 +191,40 @@ def give_item(self, data):
190191 self .protocol .send_chat_message ("Couldn't find name: %s" % name )
191192 return False
192193
194+ @permissions (UserLevels .ADMIN )
195+ def mute (self , data ):
196+ """Mute a player. Syntax: /mute [player name]"""
197+ name = " " .join (data )
198+ player = self .player_manager .get_logged_in_by_name (name )
199+ target_protocol = self .protocol .factory .protocols [player .protocol ]
200+ if player is None :
201+ self .protocol .send_chat_message ("Couldn't find name: %s" % name )
202+ return
203+ player .muted = True
204+ target_protocol .send_chat_message ("You have been muted." )
205+ self .protocol .send_chat_message ("%s has been muted." % name )
206+
207+ @permissions (UserLevels .ADMIN )
208+ def unmute (self , data ):
209+ """Unmute a currently muted player. Syntax: /unmute [player name]"""
210+ name = " " .join (data )
211+ player = self .player_manager .get_logged_in_by_name (name )
212+ target_protocol = self .protocol .factory .protocols [player .protocol ]
213+ if player is None :
214+ self .protocol .send_chat_message ("Couldn't find name: %s" % name )
215+ return
216+ player .muted = False
217+ target_protocol .send_chat_message ("You have been unmuted." )
218+ self .protocol .send_chat_message ("%s has been unmuted." % name )
219+
220+
221+ class MuteManager (BasePlugin ):
222+ name = "mute_manager"
223+ def on_chat_sent (self , data ):
224+ data = chat_sent ().parse (data .data )
225+ if self .protocol .player .muted and data .message [0 ] != self .config .command_prefix and data .message [:2 ] != "##" :
226+ self .protocol .send_chat_message ("You are currently muted and cannot speak. You are limited to commands and admin chat (prefix your lines with ## for admin chat." )
227+ return False
228+ return True
229+
230+
0 commit comments