Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2016 Luigi Martinelli <xdefconhd@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Luigi Martinelli <xdefconhd@gmail.com>
- *
- */
- registerPlugin({
- name: 'Online Users',
- version: '1.0',
- description: 'This script will monitor and save in a channel the highest number of concurrent online users',
- author: 'Luigi M. - xDefcon (xdefconhd@gmail.com)',
- vars: {
- channel: {
- title: 'Channel to be updated', type: 'channel'
- }, delayTime: {
- title: 'Run a check every [seconds]',
- type: 'number',
- placeholder: 'Check online users every... (Default: 20sec).'
- }, customString: {
- title: 'Channel name (use %u to indicate the users record)',
- type: 'string',
- placeholder: 'Change the name of the channel (Example: Max online users: %u)'
- }, debugSwitch: {
- title: 'Enable debug messages?', type: 'select', options: ['no', 'yes']
- }
- }
- }, function (sinusbot, config) {
- if (typeof config.debugSwitch === 'undefined') {
- config.debugSwitch = 0;
- }
- if (typeof config.delayTime === 'undefined') {
- config.delayTime = 20;
- debug("Check delay set to 20 seconds.");
- } else if (config.delayTime < 2) {
- debug("To avoid lag/crashes, the delay MUST be greater than 2 seconds."); config.delayTime = 3;
- debug("Delay set to 3 seconds.");
- } else {
- debug("Check delay set to " + config.delayTime + " seconds.");
- }
- if (typeof config.channel === 'undefined') {
- debug("No channel selected, SCRIPT STOPPED.");
- return;
- }
- setInterval(onlineCheck, config.delayTime * 1000);
- function debug(msg) {
- if (config.debugSwitch == 1) {
- sinusbot.log("[DEBUG] " + msg);
- }
- }
- function onlineCheck() {
- var nowOnline = getClients();
- var channel = sinusbot.getChannel(config.channel);
- var name = channel.name;
- var chanName;
- varchanName = config.customString.replace("%u", nowOnline);
- sinusbot.channelUpdate(config.channel, {name: chanName});
- }
- function getClients() {
- var channel, channels, x = 0;
- channels = sinusbot.getChannels();
- for (var i = 0; i < channels.length; i++) {
- channel = channels[i];
- for (client c : channel.clients) {
- if (c.clientServerGroups.contains("1000")) x ++;
- }
- return x;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement