SHARE
TWEET

Untitled

a guest Oct 13th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. registerPlugin({
  2.     name: "Client Status in Channel Name",
  3.     version: "1.0",
  4.     description: "-",
  5.     author: "kajo",
  6.     backends: ["ts3"],
  7.     engine: ">= 1.0",
  8.     autorun: false,
  9.     enableWeb: false,
  10.     hidden: false,
  11.     requiredModules: [],
  12.     vars: [{
  13.         name: "clientStatusInChannelNameList",
  14.         type: "array",
  15.         title: "Configuration:",
  16.         vars: [{
  17.                 name: "channelID",
  18.                 type: "string",
  19.                 title: "Channel ID:",
  20.                 placeholder: "69"
  21.             },
  22.             {
  23.                 name: "clientUID",
  24.                 type: "string",
  25.                 title: "Client UID:",
  26.                 placeholder: "/Yst8oyDYEMkdNqR+zHRpXllbgA="
  27.             },
  28.             {
  29.                 name: "channelName",
  30.                 type: "string",
  31.                 title: "Channel name [Placeholder: %status%, %symbol%]:",
  32.                 placeholder: "%symbol% Owner [%status%]"
  33.             },
  34.             {
  35.                 name: "blockHide",
  36.                 type: "checkbox",
  37.                 title: "Check this box, to block this client from using hide command"
  38.             }
  39.         ]
  40.     }, {
  41.         name: "textOnline",
  42.         type: "string",
  43.         title: "Online text (%status%):",
  44.         placeholder: "ONLINE",
  45.         default: "ONLINE"
  46.     }, {
  47.         name: "textOffline",
  48.         type: "string",
  49.         title: "Offline text (%status%):",
  50.         placeholder: "OFFLINE",
  51.         default: "OFFLINE"
  52.     }, {
  53.         name: "textAway",
  54.         type: "string",
  55.         title: "Away text (%status%):",
  56.         placeholder: "AWAY",
  57.         default: "AWAY"
  58.     }, {
  59.         name: "symbolOnline",
  60.         type: "string",
  61.         title: "Online symbol (%symbol%) [ONE CHARACTER ONLY]:",
  62.         placeholder: "✅",
  63.         default: "✅"
  64.     }, {
  65.         name: "symbolOffline",
  66.         type: "string",
  67.         title: "Offline symbol (%symbol%) [ONE CHARACTER ONLY]:",
  68.         placeholder: "❌",
  69.         default: "❌"
  70.     }, {
  71.         name: "symbolAway",
  72.         type: "string",
  73.         title: "Away symbol (%symbol%) [ONE CHARACTER ONLY]:",
  74.         placeholder: "💼",
  75.         default: "💼"
  76.     }, {
  77.         name: "commandToggleHide",
  78.         type: "string",
  79.         title: "Command to make yourself hidden (bot will think, that you are offline):",
  80.         placeholder: "!togglehide",
  81.         default: "!togglehide"
  82.     }, {
  83.         name: "awayEnabled",
  84.         title: "Whether to use away text when AFK, or online text when AFK? [CHECK to use away text when AFK]",
  85.         type: "checkbox"
  86.     }, {
  87.         name: "awayChannels",
  88.         title: "Channels (IDs), that if client is in, he is considered as AWAY",
  89.         type: "strings"
  90.     }, {
  91.         name: "showTranslation",
  92.         title: "Show translation?",
  93.         type: "checkbox"
  94.     }, {
  95.         name: "messageHidden",
  96.         type: "string",
  97.         title: "MESSAGE: You are now hidden!",
  98.         default: "You are now hidden!",
  99.         placeholder: "Translate this message here!",
  100.         conditions: [{
  101.             field: "showTranslation",
  102.             value: 1,
  103.         }]
  104.     }, {
  105.         name: "messageNotHidden",
  106.         type: "string",
  107.         title: "MESSAGE: You are not hidden anymore!",
  108.         default: "You are not hidden anymore!",
  109.         placeholder: "Translate this message here!",
  110.         conditions: [{
  111.             field: "showTranslation",
  112.             value: 1,
  113.         }]
  114.     }, {
  115.         name: "messageNoRights",
  116.         type: "string",
  117.         title: "(To disable this message, write DISABLED) MESSAGE: You do not have permission to hide yourself!",
  118.         default: "You do not have permission to hide yourself!",
  119.         placeholder: "Translate this message here!",
  120.         conditions: [{
  121.             field: "showTranslation",
  122.             value: 1,
  123.         }]
  124.     }],
  125.     voiceCommands: []
  126. }, function(_, config, meta) {
  127.  
  128.     const backend = require("backend");
  129.     const engine = require("engine");
  130.     const store = require("store");
  131.     const event = require("event");
  132.  
  133.     if (config.symbolOnline.length != 1) {
  134.         config.symbolOnline = "✅";
  135.         engine.log("Your online symbol can have only one character!");
  136.     }
  137.  
  138.     if (config.symbolOffline.length != 1) {
  139.         config.symbolOffline = "❌";
  140.         engine.log("Your offline symbol can have only one character!");
  141.     }
  142.  
  143.     if (config.symbolAway.length != 1) {
  144.         config.symbolAway = "💼";
  145.         engine.log("Your away symbol can have only one character!");
  146.     }
  147.  
  148.     let blockHideList = {};
  149.  
  150.     config.clientStatusInChannelNameList.forEach(i => {
  151.         let blockHide = i.blockHide;
  152.         let clientUID = i.clientUID;
  153.         blockHideList[clientUID] = blockHide;
  154.     });
  155.  
  156.     event.on("chat", chatInfo => {
  157.         let message = chatInfo.text.toLowerCase();
  158.         let client = chatInfo.client;
  159.         let clientUID = client.uid();
  160.  
  161.         if (message.startsWith(config.commandToggleHide.toLowerCase())) {
  162.             let data = store.get(clientUID);
  163.             let blockHide = blockHideList[clientUID];
  164.  
  165.             if (!blockHide) {
  166.                 if (!data) {
  167.                     store.set(clientUID, { hidden: true });
  168.                     client.chat(config.messageHidden);
  169.                 } else if (data.hidden === false) {
  170.                     store.set(clientUID, { hidden: true });
  171.                     client.chat(config.messageHidden);
  172.                 } else if (data.hidden === true) {
  173.                     store.set(clientUID, { hidden: false });
  174.                     client.chat(config.messageNotHidden);
  175.                 }
  176.             } else {
  177.                 if (config.messageNoRights.toLowerCase() !== "disabled")
  178.                     client.chat(config.messageNoRights);
  179.             }
  180.         }
  181.     });
  182.  
  183.     setInterval(() => {
  184.         if (backend.isConnected()) {
  185.             config.clientStatusInChannelNameList.forEach(i => {
  186.                 let channelID = i.channelID;
  187.                 let clientUID = i.clientUID;
  188.                 let channelName = i.channelName;
  189.                 let blockHide = i.blockHide;
  190.  
  191.                 let channel = backend.getChannelByID(channelID);
  192.  
  193.                 if (channel) {
  194.                     let client = backend.getClientByUID(clientUID);
  195.  
  196.                     if (!blockHide && client) {
  197.                         let clientData = store.get(client.uid());
  198.  
  199.                         if (clientData !== undefined)
  200.                             if (clientData.hidden === true)
  201.                                 client = undefined;
  202.                     }
  203.  
  204.                     let clientAFK = (client && config.awayEnabled) ? (client.isAway() || checkArrays(client.getChannels().map(ch => ch.id()), config.awayChannels)) : false;
  205.  
  206.                     let status = (client) ? ((clientAFK) ? config.textAway : config.textOnline) : config.textOffline;
  207.                     let symbol = (client) ? ((clientAFK) ? config.symbolAway : config.symbolOnline) : config.symbolOffline;
  208.                     let name = channelName.replace("%status%", status).replace("%symbol%", symbol);
  209.                     channel.setName(name);
  210.                 }
  211.             });
  212.         }
  213.     }, 30 * 1000);
  214.  
  215.     /**
  216.      * Checking if two arrays have at least one same item
  217.      * @param  {array} arr1 First array
  218.      * @param  {array} arr2 Second array
  219.      * @return {boolean}      Whether they have / don't have at least one same item
  220.      */
  221.     function checkArrays(arr1, arr2) {
  222.         if (arr1 === arr2)
  223.             return true;
  224.  
  225.         if (arr1 === undefined || arr2 === undefined)
  226.             return false;
  227.  
  228.         return arr2.some(item => arr1.includes(item));
  229.     }
  230.  
  231.     // SCRIPT LOADED SUCCCESFULLY
  232.     engine.log("\n[Script] \"" + meta.name + "\" [Version] \"" + meta.version + "\" [Author] \"" + meta.author + "\"");
  233. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top