<commit_before>###

Copyright (c) 2011-2013  Voicious

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU Affero General Public License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this
program. If not, see <http://www.gnu.org/licenses/>.

###


class CommandManager
    # Initialize the Command Manager and set the callbacks for the Event Manager.
    constructor     : (@emitter) ->
        @emitter.on 'chat.cmd', (event, data) =>
            @parseCmd data
        @emitter.on 'cmd.kick', (event, data) =>
            @onKick data

    # Parse the command and call the right function.
    parseCmd        : (command) =>
        cmd = command.cmd.split(' ')
        user = command.from
        switch  cmd[0]
            when 'kick' then do () =>
                if cmd[1]?
                    if cmd[2]?
                        @kick cmd[1], cmd[2]
                    else
                        @kick cmd[1], ""
                else
                    @emitter.trigger 'chat.error', { text: cmd[0] + ": usage: /kick user reason"}
            else
                @emitter.trigger 'chat.error', { text: cmd[0] + ": command not found." }

    # Kick command implementation
    kick            : (user, reason) =>
        message = { type : 'cmd.kick', to : user, params : { message : reason } }
        @emitter.trigger 'message.sendToOneName', message

    onKick          : (data) =>
        #document.cookie = 'connect.sid=; expires=Thu, 01-Jan-70 00:00:01 GMT;'
        console.log data
        text    = "#{window.Voicious.currentUser.name} has been kicked out! (#{data.message})"
        message = { type : 'chat.error', params : { text : text } }
        @emitter.trigger 'message.sendtoall', message
        window.location.replace '/'

if window?
    window.CommandManager   = CommandManager<commit_msg>authorize spaces in kick reason, fixes #98<commit_after>###

Copyright (c) 2011-2013  Voicious

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU Affero General Public License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this
program. If not, see <http://www.gnu.org/licenses/>.

###


class CommandManager
    # Initialize the Command Manager and set the callbacks for the Event Manager.
    constructor     : (@emitter) ->
        @emitter.on 'chat.cmd', (event, data) =>
            @parseCmd data
        @emitter.on 'cmd.kick', (event, data) =>
            @onKick data

    # Parse the command and call the right function.
    parseCmd        : (command) =>
        cmd = command.cmd.split(' ')
        user = command.from
        switch  cmd[0]
            when 'kick' then do () =>
                if cmd[1]?
                    reason = ''
                    if cmd[2]?
                        reason = (cmd.splice 2).join ' '
                    @kick cmd[1], reason
                else
                    @emitter.trigger 'chat.error', { text: cmd[0] + ": usage: /kick user [reason]"}
            else
                @emitter.trigger 'chat.error', { text: cmd[0] + ": command not found." }

    # Kick command implementation
    kick            : (user, reason) =>
        message = { type : 'cmd.kick', to : user, params : { message : reason } }
        @emitter.trigger 'message.sendToOneName', message

    onKick          : (data) =>
        #document.cookie = 'connect.sid=; expires=Thu, 01-Jan-70 00:00:01 GMT;'
        console.log data
        text    = "#{window.Voicious.currentUser.name} has been kicked out! (#{data.message})"
        message = { type : 'chat.error', params : { text : text } }
        @emitter.trigger 'message.sendtoall', message
        window.location.replace '/'

if window?
    window.CommandManager   = CommandManager
{'fraction_non_alphanumeric': 0.10262008733624454, 'fraction_numerical': 0.012008733624454149, 'mean_word_length': 2.18567454798331, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '651010', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1191, 'n_words': 466}