Some bugs that I found (+ solution)


#1

PhantomBot Version: 2.3.9
OS Version: Ubuntu 16.04
Java Version: Java 8
Browser and Version (for Panel Support): Opera 48.0
Stock PhantomBot: No
Any Recent Changes to Your System: No

Description of Issue:
Most of these bugs I found on the september’s night builds, but I also checked, it is still there in the code of 2.3.9 Stable. Below, I will add names of the files and lines where code begins. First block will contain the original code. Second - with changes.

Removing brackets from a default value of an argument.
commands/customCommands.js - 137

    if (message.match(/\(1=[^)]+\)/g)) {
        if (event.getArgs()[0]) {
            var t = message.match(/\(1=[^)]+\)/)[0];
            message = $.replace(message, t, event.getArgs()[0]);
        }
        message = $.replace(message, '(1=', '(');
    }

    if (message.match(/\(1=[^)]+\)/g)) {
	var t = message.match(/\(1=[^)]+\)/)[0];
        if (event.getArgs()[0]) {
            message = $.replace(message, t, event.getArgs()[0]);
        } else {
            var tR = t.replace('(1=', '').replace(')', '');
            message = $.replace(message, t, tR);
        }
    }

Missing “$.” before systemTime() function.
core/misc.js - 158

    if (((timeout + 10000) > systemTime()) || !run) {
        return;
    }

    if (((timeout + 10000) > $.systemTime()) || !run) {
        return;
    }

Fixing dublicates (in the points table) of those nicknames that contains capital letters.
handlers/subscribeHandler.js - 60 and 85

            $.inidb.incr('points', subscriber, subReward);

            $.inidb.incr('points', subscriber.toLowerCase(), subReward);

handlers/subscribeHandler.js - 123

	$.inidb.incr('points', resubscriber, reSubReward);

	$.inidb.incr('points', resubscriber.toLowerCase(), reSubReward);

Ticket raffle entries counter was counting the same users, that had already bought tickets earlier.
systems/ticketraffleSystem.js - 157

        totalEntries++;

	if (!$.inidb.exists('entered', user.toLowerCase())) {
	    totalEntries++;
	}

Missing an argument when checking subcommands permission in discord.
init.js - 505

        if (isAdmin == false && $.discord.permCom(command, (args[0] !== undefined && $.discord.subCommandExists(args[0].toLowerCase()) ? args[0].toLowerCase() : '')) !== 0) {
            return;
        }

        if (isAdmin == false && $.discord.permCom(command, (args[0] !== undefined && $.discord.subCommandExists(command, args[0].toLowerCase()) ? args[0].toLowerCase() : '')) !== 0) {
            return;
        }

Incorrect work of function, when trying to add a list of channels through the !channelcom command.
discord/commands/customCommands.js - 457

        $.inidb.set('discordChannelcom', action, subAction);
        $.discord.clearChannelCommands(action);
        $.discord.setCommandChannel(action, subAction, false);
        $.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.success', action, subAction));

        $.discord.clearChannelCommands(action);
		var key = [];
		for (var i in args) {
			if (i != 0) {
				args[i] = args[i].replace(',', '').toLowerCase();
				$.discord.setCommandChannel(action, args[i], false);
				key.push(args[i]);
			}
		}
		key = key.join(', ');
		$.inidb.set('discordChannelcom', action, key);
        $.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.success', action, key));

“.discord” repeats in that string twice.
discord/games/gambling.js - 80

	$.discord.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));

	$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));

Impossible to set “0” value through the web panel.
web/panel/js/pointsPanel.js - 316

    if (value.indexOf('.') !== -1 || parseInt(value) < 1) {

    if (value.indexOf('.') !== -1 || (parseInt(value) < 1 && parseInt(value) !== 0)) {

Sometimes I accidentally copied nicknames with spaces, and it created dublicates in points database.
web/panel/js/pointsPanel.js - 364

function modifyUserPoints(action) {
    var username = $("#adjustUserPointsNameInput").val(),
        points = $("#adjustUserPointsInput").val();

function modifyUserPoints(action) {
    var username = $("#adjustUserPointsNameInput").val(),
        points = $("#adjustUserPointsInput").val();
    username = username.replace(/\s+/g, '');

Some fixes for discord web panel.

Missing “alias” variable.
web/panel/js/discordPanel.js - 110

        var keys = msgObject['results'],
            html = '<table style="width: 100%"><tr><th>Command</th><th>Response</th><th>Cooldown</th><th style="float: right;"></td>',
            dataObj = {},
            permission,
            cost,
            cooldown,
            response,
            command,
            channel,
            global;

        var keys = msgObject['results'],
            html = '<table style="width: 100%"><tr><th>Command</th><th>Response</th><th>Cooldown</th><th style="float: right;"></td>',
            dataObj = {},
	    command,
	    response,
            permission,
            cost,
            cooldown,
	    global,
            channel,
	    alias;

There is no defining of “alias”.
web/panel/js/discordPanel.js - 163

            if (keys[i]['table'] == 'discordCommands') {
                command = keys[i]['key'];
                response = keys[i]['value'];
                permission = dataObj[command].permission;
                channel = (dataObj[command] !== undefined && dataObj[command].channel === undefined ? '' : dataObj[command].channel);
                cooldown = (dataObj[command] !== undefined && dataObj[command].cooldown === undefined ? 0 : dataObj[command].cooldown);
                cost = (dataObj[command] !== undefined && dataObj[command].cost === undefined ? 0 : dataObj[command].cost);
                global = (dataObj[command] !== undefined && dataObj[command].isGlobal === undefined ? true : dataObj[command].isGlobal);

            if (keys[i]['table'] == 'discordCommands') {
                command = keys[i]['key'];
                response = keys[i]['value'];
                permission = dataObj[command].permission;
		cost = (dataObj[command] !== undefined && dataObj[command].cost === undefined ? 0 : dataObj[command].cost);
                cooldown = (dataObj[command] !== undefined && dataObj[command].cooldown === undefined ? 0 : dataObj[command].cooldown);
                global = (dataObj[command] !== undefined && dataObj[command].isGlobal === undefined ? true : dataObj[command].isGlobal);             
                channel = (dataObj[command] !== undefined && dataObj[command].channel === undefined ? '' : dataObj[command].channel);
		alias = (dataObj[command] !== undefined && dataObj[command].alias === undefined ? '' : dataObj[command].alias);

Also “alias” is missing.
web/panel/js/discordPanel.js - 175

                    '<td style="float: right;"><button type="button" class="btn btn-default btn-xs" onclick="$.openCommandModal(\'' + command + '\', \'' + response.replace(/\'/g, '&#39;') + '\', \'' + permission + '\', \'' + cost + '\', \'' + cooldown + '\', \'' + channel + '\', \'' + global +'\')"><i class="fa fa-pencil" /> </button>' +

                    '<td style="float: right;"><button type="button" class="btn btn-default btn-xs" onclick="$.openCommandModal(\'' + command + '\', \'' + response.replace(/\'/g, '&#39;') + '\', \'' + permission + '\', \'' + cost + '\', \'' + cooldown + '\', \'' + global + '\', \'' + channel + '\', \'' + alias +'\')"><i class="fa fa-pencil" /> </button>' +

Writing “alias” in the database.
web/panel/js/discordPanel.js - 195

    sendDBKeysList('discord_commands', ['discordCommands', 'discordCooldown', 'discordPermcom', 'discordChannelcom']);

    sendDBKeysList('discord_commands', ['discordCommands', 'discordCooldown', 'discordPermcom', 'discordChannelcom', 'discordAliascom']);

Adding “alias” links.
web/panel/js/discordPanel.js - 230

function resetHtmlValues() {
    $('#command-name-modal').val('');
    $('#command-response-modal').val('');
    $('#command-permission-modal').val('');
    $('#command-cooldown-modal').val('');
    $('#command-channel-modal').val();
    $('#command-add-name-modal').val('');
    $('#command-add-response-modal').val('');
    $('#command-add-permission-modal').val('0');
    $('#command-add-cooldown-modal').val('0');
    $('#command-add-cost-modal').val('0');
    $('#command-add-channel-modal').val('');
    $('#command-add-global').prop('checked', true);
    $('#command-edit-global').prop('checked', true);
}

function resetHtmlValues() {
    $('#command-name-modal').val('');
    $('#command-response-modal').val('');
    $('#command-permission-modal').val('');
    $('#command-cost-modal').val('');
    $('#command-cooldown-modal').val('');
    $('#command-edit-global').prop('checked', true);
    $('#command-channel-modal').val('');
    $('#command-alias-modal').val('');
    $('#command-add-name-modal').val('');
    $('#command-add-response-modal').val('');
    $('#command-add-permission-modal').val('0');
    $('#command-add-cost-modal').val('0');
    $('#command-add-cooldown-modal').val('0');
    $('#command-add-global').prop('checked', true);
    $('#command-add-channel-modal').val('');
    $('#command-add-alias-modal').val('');
}

“checked” option wasn’t sending proper status from the discord web panel.
web/panel/js/discordPanel.js - 260

        var command = ($('#command-name-modal').val().length === 0 ? $('#command-add-name-modal').val() : $('#command-name-modal').val()),
            response = ($('#command-response-modal').val().length === 0 ?  $('#command-add-response-modal').val() : $('#command-response-modal').val()),
            permission = ($('#command-permission-modal').val().length === 0 ?  $('#command-add-permission-modal').val() : $('#command-permission-modal').val()),
            cooldown = ($('#command-cooldown-modal').val().length === 0 ? $('#command-add-cooldown-modal').val() : $('#command-cooldown-modal').val()),
            channel = ($('#command-channel-modal').val().length === 0 ? $('#command-add-channel-modal').val() : $('#command-channel-modal').val()),
            price = ($('#command-cost-modal').val().length === 0 ? $('#command-add-cost-modal').val() : $('#command-cost-modal').val()),
            alias = ($('#command-alias-modal').val().length === 0 ? $('#command-add-alias-modal').val() : $('#command-alias-modal').val()),
            checked = ($('#command-add-global').is(':checked'));

        var command = ($('#command-name-modal').val().length === 0 ? $('#command-add-name-modal').val() : $('#command-name-modal').val()),
            response = ($('#command-response-modal').val().length === 0 ?  $('#command-add-response-modal').val() : $('#command-response-modal').val()),
            permission = ($('#command-permission-modal').val().length === 0 ?  $('#command-add-permission-modal').val() : $('#command-permission-modal').val()),
	    price = ($('#command-cost-modal').val().length === 0 ? $('#command-add-cost-modal').val() : $('#command-cost-modal').val()),
            cooldown = ($('#command-cooldown-modal').val().length === 0 ? $('#command-add-cooldown-modal').val() : $('#command-cooldown-modal').val()),
	    checked = ($('#command-name-modal').val().length === 0 ? $('#command-add-global').is(':checked') : $('#command-edit-global').is(':checked')),
            channel = ($('#command-channel-modal').val().length === 0 ? $('#command-add-channel-modal').val() : $('#command-channel-modal').val()),
            alias = ($('#command-alias-modal').val().length === 0 ? $('#command-add-alias-modal').val() : $('#command-alias-modal').val());

Fixed adding channels.
web/panel/js/discordPanel.js - 282

        if (channel.length === 0) {
            sendDBDelete('discord_command', 'discordChannelcom', command);
        }

        if (channel.length > 0) {
	    sendDBUpdate('discord_command', 'discordChannelcom', command, channel.toString());
	} else {
            sendDBDelete('discord_command', 'discordChannelcom', command);
        }

Missing “alias” argument.
web/panel/js/discordPanel.js - 299

function openCommandModal(command, response, permission, cost, cooldown, channel, checked) {
    $('#command-name-modal').val(command);
    $('#command-response-modal').val(response.replace(/&#39;/g, '\''));
    $('#command-permission-modal').val(permission);
    $('#command-cooldown-modal').val(cooldown);
    $('#command-channel-modal').val(channel);
    $('#command-cost-modal').val(cost);
    $('#command-edit-global').prop('checked', checked == 'true');

    $('#command-modal').modal();
}

function openCommandModal(command, response, permission, cost, cooldown, checked, channel, alias) {
    $('#command-name-modal').val(command);
    $('#command-response-modal').val(response.replace(/&#39;/g, '\''));
    $('#command-permission-modal').val(permission);
    $('#command-cost-modal').val(cost);
    $('#command-cooldown-modal').val(cooldown);
    $('#command-edit-global').prop('checked', checked == 'true');
    $('#command-channel-modal').val(channel);
    $('#command-alias-modal').val(alias);
    
    $('#command-modal').modal();
}

I hope this code is correct. You can double check it. :wink:
Though when I tested it, all seemed to be working ok.


#2

Please open a pull request on our Github it’s much easier for us to review, and gives you credit.


#3

@kojitsari Never did that, but I will try to sort it out. Thanks! :slightly_smiling_face:


#4

The guide on this site covers everything you’d need, and probably more. It’s really not hard to do once you’ve already done it once or twice.


#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.