javascript/features/playground/playground_commands.js
// Communication that contains one (or more) of these words will be blocked.
Communication that contains one (or more) of these words will be blocked.
Communication that contains one ( or more ) of these words will be blocked .
async handleBlockedWords(player) {
        const words = this.communication_().getBlockedWords();
        const substitutions = this.communication_().getReplacements();
        const menu = new Menu('Blocked words', ['Blocked word', 'Added by']);
        menu.addItem('Block a new word', '-', async () => {
            const wordToBlock = await Question.ask(player, {
                question: 'Blocked words',
                message: 'Which word do you want to block?',
                constraints: {
                    validation: /^.{3,24}$/i,
                    explanation: 'The word must be between 3 and 24 characters in length.',
                    abort: 'Sorry, you did not enter a valid word to block.',
                }
            });
            if (!wordToBlock)
                return;  
            const lowerCaseWordToBlock = wordToBlock.trim().toLowerCase();
            for (const existingWord of words) {
                if (existingWord.word !== lowerCaseWordToBlock)
                    continue;
                return alert(player, {
                    title: 'Blocked words',
                    message: `The word "${lowerCaseWordToBlock}" has already been blocked.`
                });
            }
            for (const existingSubstitution of substitutions) {
                if (existingSubstitution.before !== lowerCaseWordToBlock)
                    continue;
                return alert(player, {
                    title: 'Blocked words',
                    message: `The word "${lowerCaseWordToBlock}" already exists as a substitution.`
                });
            }
            this.communication_().addBlockedWord(player, lowerCaseWordToBlock);
            this.announce_().announceToAdministrators(
                Message.LVP_ANNOUNCE_WORD_BLOCKED, player.name, player.id, lowerCaseWordToBlock);
            return alert(player, {
                title: 'Blocked words',
                message: `The word "${lowerCaseWordToBlock}" has been blocked on the server.`
            });
        });
        menu.addItem('-----', '-----');
        for (const { word, nickname } of words.sort()) {
            menu.addItem(word, nickname, async() => {
                const confirmation = await confirm(player, {
                    title: 'Blocked words',
                    message: `Are you sure that you want to unblock the word "${word}"?`,
                });
                if (!confirmation)
                    return;  
                this.communication_().removeBlockedWord(player, word);
                this.announce_().announceToAdministrators(
                    Message.LVP_ANNOUNCE_WORD_UNBLOCKED, player.name, player.id, word);
                return alert(player, {
                    title: 'Blocked words',
                    message: `The word "${word}" has been unblocked on the server.`
                });
            });
        }
        await menu.displayForPlayer(player);
    }
async handleBlockedWords ( player ) { const words = this . communication_ ( ) . getBlockedWords ( ) ; const substitutions = this . communication_ ( ) . getReplacements ( ) ; const menu = new Menu ( 'Blocked words' , [ 'Blocked word' , 'Added by' ] ) ; menu . addItem ( 'Block a new word' , '-' , async ( ) => { const wordToBlock = await Question . ask ( player , { question : 'Blocked words' , message : 'Which word do you want to block?' , constraints : { validation : / ^.{3,24}$ / i , explanation : 'The word must be between 3 and 24 characters in length.' , abort : 'Sorry, you did not enter a valid word to block.' , } } ) ; if ( ! wordToBlock ) return ; const lowerCaseWordToBlock = wordToBlock . trim ( ) . toLowerCase ( ) ; for ( const existingWord of words ) { if ( existingWord . word !== lowerCaseWordToBlock ) continue ; return alert ( player , { title : 'Blocked words' , message : ` ${ lowerCaseWordToBlock } ` } ) ; } for ( const existingSubstitution of substitutions ) { if ( existingSubstitution . before !== lowerCaseWordToBlock ) continue ; return alert ( player , { title : 'Blocked words' , message : ` ${ lowerCaseWordToBlock } ` } ) ; } this . communication_ ( ) . addBlockedWord ( player , lowerCaseWordToBlock ) ; this . announce_ ( ) . announceToAdministrators ( Message . LVP_ANNOUNCE_WORD_BLOCKED , player . name , player . id , lowerCaseWordToBlock ) ; return alert ( player , { title : 'Blocked words' , message : ` ${ lowerCaseWordToBlock } ` } ) ; } ) ; menu . addItem ( '-----' , '-----' ) ; for ( const { word , nickname } of words . sort ( ) ) { menu . addItem ( word , nickname , async ( ) => { const confirmation = await confirm ( player , { title : 'Blocked words' , message : ` ${ word } ` , } ) ; if ( ! confirmation ) return ; this . communication_ ( ) . removeBlockedWord ( player , word ) ; this . announce_ ( ) . announceToAdministrators ( Message . LVP_ANNOUNCE_WORD_UNBLOCKED , player . name , player . id , word ) ; return alert ( player , { title : 'Blocked words' , message : ` ${ word } ` } ) ; } ) ; } await menu . displayForPlayer ( player ) ; }
Communication that contains one (or more) of these words will be blocked.
Communication that contains one ( or more ) of these words will be blocked .
// the |player| abandoned the flow // Verify that the |lowerCaseWordToBlock| has not already been blocked on the server. // Verify that the |lowerCaseWordToBlock| hasn't already been added as a substitution. // Actually block the |lowerCaseWordToBlock| now. // Inform administrators of the newly blocked word. // Confirm the action to the |player|. // Add a delimiter before listing all the currently blocked words. // the |player| abandoned the flow // Actually remove the |word| from the blocked word list. // Inform administrators of the re-allowed word. // Confirm the action to the |player|.