Guest User

extremesupport.js

a guest
Mar 23rd, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. CREATE TABLE IF NOT EXISTS `log` (
  3.   `datum` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  4.   `supporterName` varchar(32) NOT NULL,
  5.   `supporterUid` varchar(128) NOT NULL,
  6.   `configGroup` varchar(128) NOT NULL,
  7.   `userName` varchar(32) NOT NULL,
  8.   `userUid` varchar(128) NOT NULL,
  9.   `fromChannelName` varchar(32) NOT NULL,
  10.   `fromChannelId` int(11) NOT NULL,
  11.   `toChannelName` varchar(32) NOT NULL,
  12.   `toChannelId` int(11) NOT NULL
  13. );
  14.  
  15. CREATE VIEW view_infolog AS SELECT
  16. (SELECT datum FROM log WHERE supporterUid = A1.supporterUid ORDER BY datum DESC LIMIT 1) AS lastDate,
  17. (SELECT supporterName FROM log WHERE supporterUid = A1.supporterUid ORDER BY datum DESC LIMIT 1) AS lastName,
  18. (SELECT configGroup FROM log WHERE supporterUid = A1.supporterUid ORDER BY datum DESC LIMIT 1) AS lastGroup,
  19. (SELECT Count(*) FROM log WHERE supporterUid = A1.supporterUid AND TIMEDIFF(current_timestamp, datum) <= 240000 ORDER BY datum DESC LIMIT 1) AS last24h,
  20. (SELECT Count(*) FROM log WHERE supporterUid = A1.supporterUid AND DATEDIFF(current_timestamp, datum) <= 7 ORDER BY datum DESC LIMIT 1) AS last7d,
  21. (SELECT Count(*) FROM log WHERE supporterUid = A1.supporterUid AND DATEDIFF(current_timestamp, datum) <= 30 ORDER BY datum DESC LIMIT 1) AS lastMonth,
  22. Count(*) AS total,
  23. supporterUid
  24. FROM `log` A1 WHERE 1 GROUP BY supporterUid ORDER BY datum DESC
  25.  
  26. */
  27.  
  28.  
  29. registerPlugin({
  30.     name: 'extremesupport',
  31.     version: '1.0',
  32.     description: 'Dieses Script unterstützt viele Support-Optionen.',
  33.     author: 'Dennis Hoffmann',
  34.     engines: '>= 0.9.16',
  35.     vars: [
  36.         //Supporter Groups (GroupId, GroupName, Permissions, Channels[ChannelId, timeToMessage]
  37.         {
  38.             name: 'groups',
  39.             title: 'Groups',
  40.             type: 'array',
  41.             vars: [
  42.                 {name: 'id', title: 'Group Id', type: 'number'},
  43.                 {name: 'name', title: 'Group Name', type: 'string'},
  44.                 {name: 'permissions', title: 'Group Permissions', type: 'string'},
  45.                 {
  46.                     name: 'channels',
  47.                     title: 'Support Channels',
  48.                     type: 'array',
  49.                     vars: [
  50.                         {name: 'id', title: 'Channel Id', type: 'channel'},
  51.                         {name: 'time', title: 'Time to Info-Message', type: 'number'}
  52.                     ]
  53.                 }
  54.             ]
  55.         },
  56.  
  57.         //Supporter Users (UserUid, UserName, Permissions, Channels[ChannelId, timeToMessage]
  58.         {
  59.             name: 'users',
  60.             title: 'Users',
  61.             type: 'array',
  62.             vars: [
  63.                 {name: 'uid', title: 'Users Uid', type: 'string'},
  64.                 {name: 'name', title: 'User Name', type: 'string'},
  65.                 {name: 'permissions', title: 'User Permissions', type: 'string'},
  66.                 {
  67.                     name: 'channels',
  68.                     title: 'Support Channels',
  69.                     type: 'array',
  70.                     vars: [
  71.                         {name: 'id', title: 'Channel Id', type: 'channel'},
  72.                         {name: 'time', title: 'Time to Info-Message', type: 'number'}
  73.                     ]
  74.                 }
  75.             ]
  76.         },
  77.  
  78.         //Support Log Channels (ChannelId)
  79.         {
  80.             name: 'logs',
  81.             title: 'Log-Channels',
  82.             type: 'array',
  83.             vars: [
  84.                 {name: 'id', title: 'Channel Id', type: 'channel'}
  85.             ]
  86.         },
  87.  
  88.         //Support Info Channels (ChannelId, MessageType, Message)
  89.         {
  90.             name: 'infos',
  91.             title: 'Info-Channels',
  92.             type: 'array',
  93.             vars: [
  94.                 {name: 'id', title: 'Channel Id', type: 'channel'},
  95.                 {name: 'type', title: 'Message Type', type: 'select', options: ['Poke', 'Chat']},
  96.                 {name: 'message', title: 'Message', type: 'multiline'}
  97.             ]
  98.         },
  99.  
  100.         {
  101.             name: 'blockedchannels',
  102.             title: 'Blocked Channels',
  103.             type: 'array',
  104.             vars: [
  105.                 {name: 'id', title: 'Channel Id', type: 'channel'}
  106.             ]
  107.         },
  108.  
  109.         { name: 'supportWarteraum', title: 'Support Warteraum', type: 'channel'},
  110.  
  111.         {
  112.             name: 'autoSupports',
  113.             title: 'Auto Support',
  114.             type: 'array',
  115.             vars: [
  116.                 {name: 'supmenuid', title: 'Support Chat Id', type: 'number'},
  117.                 {name: 'supchatmsg', title: 'Support Chat Message', type: 'multiline'},
  118.                 {name: 'supnewchannel', title: 'Move to Channel', type: 'channel'},
  119.                 {
  120.                     name: 'awnsers',
  121.                     title: 'Antworten',
  122.                     type: 'array',
  123.                     vars: [
  124.                         {name: 'value', title: 'Antwort', type: 'string'},
  125.                         {name: 'newmenuid', title: 'Neue Support Chat Id', type: 'number'}
  126.                     ]
  127.                 }
  128.             ]
  129.         }
  130.     ]
  131. }, function(sinusbot, config) {
  132.     /*
  133.     Store:
  134.     _0 Wartezeit
  135.     _1 toga
  136.     _2 menuid
  137.      */
  138.     var store = require('store');
  139.     var event = require('event');
  140.     var backend = require('backend');
  141.     var db = require('db');
  142.     var engine = require('engine');
  143.     var helpers = require('helpers');
  144.     var dbc = db.connect({ driver: 'mysql', host: '127.0.0.1', username: '******', password: '******', database: '******' }, function(err) {
  145.         if (err) { engine.log(err); }
  146.     });
  147.  
  148.     function getMenu(client){
  149.         var value = store.get(client.uid() + "_2");
  150.         if(value == null)value = -1;
  151.         return value;
  152.     }
  153.  
  154.     function setMenu(client, value){
  155.         store.set(client.uid() + "_2", value);
  156.     }
  157.  
  158.     function resetMenu(client){
  159.         store.unset(client.uid() + "_2");
  160.     }
  161.  
  162.     function getToga(client){
  163.         var value = store.get(client.uid() + "_1");
  164.         if(value == null)value = 1;
  165.         return value;
  166.     }
  167.  
  168.     function setToga(client, value){
  169.         store.set(client.uid() + "_1", value);
  170.     }
  171.  
  172.     function toggleToga(client){
  173.         if(isInAnyGroup(client) == 0){
  174.             return -1;
  175.         }
  176.         if(getToga(client) == 0){
  177.             setToga(client, 1);
  178.             return 1;
  179.         }
  180.         else {
  181.             setToga(client, 0);
  182.             return 0;
  183.         }
  184.     }
  185.    
  186.     function getGamesupport(client){
  187.         var value = store.get(client.uid() + "_3");
  188.         if(value == null)value = 0;
  189.         return value;
  190.     }
  191.  
  192.     function setGamesupport(client, value){
  193.         store.set(client.uid() + "_3", value);
  194.     }
  195.  
  196.     function toggleGamesupport(client){
  197.         if(isInAnyGroup(client) == 0){
  198.             return -1;
  199.         }
  200.         if(getGamesupport(client) == 0){
  201.             setGamesupport(client, 1);
  202.             return 1;
  203.         }
  204.         else {
  205.             setGamesupport(client, 0);
  206.             return 0;
  207.         }
  208.     }
  209.  
  210.     function ticketUnset(key){
  211.         store.unset(key + "_0");
  212.     }
  213.  
  214.     function ticketReset(key){
  215.         store.set(key + "_0", 0);
  216.     }
  217.  
  218.     function ticketGet(key){
  219.         var value = store.get(key + "_0");
  220.         if(value == null)value = -1;
  221.         return value;
  222.     }
  223.  
  224.     function ticketAdd(key){
  225.         var value = ticketGet(key) + 1;
  226.         store.set(key + "_0", value);
  227.         return value;
  228.     }
  229.  
  230.     function isSupportGroupChannel(channel){
  231.         var bool = 0;
  232.         if(channel != null && config.groups != null){
  233.             config.groups.forEach(function(group) {
  234.                 if(group.channels != null && bool == 0){
  235.                     group.channels.forEach(function(ch) {
  236.                         if(channel.id() == ch.id)bool = 1;
  237.                     });
  238.                 }
  239.             });
  240.         }
  241.         return bool;
  242.     }
  243.  
  244.     function isSupportUserChannel(channel){
  245.         var bool = 0;
  246.         if(channel != null && config.users != null){
  247.             config.users.forEach(function(user) {
  248.                 if(user.channels != null && bool == 0){
  249.                     user.channels.forEach(function(ch) {
  250.                         if(channel.id() == ch.id)bool = 1;
  251.                     });
  252.                 }
  253.             });
  254.         }
  255.         return bool;
  256.     }
  257.  
  258.     function isSupportLogChannel(channel){
  259.         var bool = 0;
  260.         if(channel != null && config.logs != null){
  261.             config.logs.forEach(function(ch) {
  262.                 if(channel.id() == ch.id)bool = 1;
  263.             });
  264.         }
  265.         return bool;
  266.     }
  267.  
  268.     function isSupportInfoChannel(channel){
  269.         var bool = 0;
  270.         if(channel != null && config.infos != null){
  271.             config.infos.forEach(function(ch) {
  272.                 if(channel.id() == ch.id)bool = 1;
  273.             });
  274.         }
  275.         return bool;
  276.     }
  277.  
  278.     function getUserConfigGroupName(client){
  279.         var value = "";
  280.         if(client != null && config.groups != null){
  281.             client.getServerGroups().forEach(function(cgroup) {
  282.                 config.groups.forEach(function (group) {
  283.                     if(cgroup.id() == group.id)value = group.name;
  284.                 });
  285.             });
  286.         }
  287.         return value;
  288.     }
  289.  
  290.     function getUserConfigUserName(client){
  291.         var value = "";
  292.         if(client != null && config.users != null){
  293.             config.users.forEach(function (user) {
  294.                 if(client.uid() == user.uid)value = user.name;
  295.             });
  296.         }
  297.         return value;
  298.     }
  299.  
  300.     function isInAnyGroup(client){
  301.         var bool = 0;
  302.         if(getUserConfigGroupName(client) != "")bool = 1;
  303.         else if(getUserConfigUserName(client) != "")bool = 1;
  304.         return bool;
  305.     }
  306.  
  307.     function log(fromChannel,toChannel,client,invoker){
  308.         if (dbc) dbc.exec("INSERT INTO log (supporterName,supporterUid,configGroup,userName,userUid,fromChannelName,fromChannelId,toChannelName,toChannelId) VALUES ('"+invoker.name()+"','"+invoker.uid()+"','"+getUserConfigGroupName(invoker)+"','"+client.name()+"','"+client.uid()+"','"+fromChannel.name()+"','"+fromChannel.id()+"','"+toChannel.name()+"','"+toChannel.id()+"')");
  309.         else invoker.chat("Es ist ein Problem mit dem Bot aufgetreten, bitte leite dies an das Management weiter.");
  310.     }
  311.  
  312.     function getClickableName(client){
  313.         var name = client.name().replace('[', '%5C%5B').replace(']', '%5C%5D').replace(' ', '%20').replace('[', '%5C%5B').replace(']', '%5C%5D').replace(' ', '%20').replace('[', '%5C%5B').replace(']', '%5C%5D').replace(' ', '%20').replace('[', '%5C%5B').replace(']', '%5C%5D').replace(' ', '%20').replace('[', '%5C%5B').replace(']', '%5C%5D').replace(' ', '%20').replace(' ', '%20').replace(' ', '%20').replace(' ', '%20').replace(' ', '%20').replace(' ', '%20').replace(' ', '%20').replace(' ', '%20');
  314.         name = "[URL=client://0/" + client.uid() + "~" + name + "]" + client.name() + "[/URL]";
  315.         return name;
  316.     }
  317.  
  318.     function getSupportMessage(client, channel){
  319.         return "[b][color=blue][Support][/color] " + getClickableName(client) + " benötigt Hilfe im [color=green]" + channel.name() + "[/color]![/b]";
  320.     }
  321.  
  322.     function sendGroupMessage(groupid, msg){
  323.         backend.getClients().forEach(function(client) {
  324.             client.getServerGroups().forEach(function(group) {
  325.                 if(group.id() == groupid && getToga(client) == 1 && !client.isDeaf() && (isInBlockedChannel(client) == 0 || getGamesupport(client) == 1))client.chat(msg);
  326.             });
  327.         });
  328.     }
  329.  
  330.     function getPermissions(client){
  331.         var perm = "";
  332.         if(client != null){
  333.             if(config.groups != null){
  334.                 client.getServerGroups().forEach(function(group) {
  335.                     config.groups.forEach(function(cgroup) {
  336.                         if(group.id() == cgroup.id){
  337.                             perm = cgroup.permissions;
  338.                         }
  339.                     });
  340.                 });
  341.             }
  342.  
  343.             if(config.users != null) {
  344.                 config.users.forEach(function (user) {
  345.                     if (user.uid == client.uid()) {
  346.                         if (perm == "") perm = user.permissions;
  347.                         else perm = perm + "," + user.permissions;
  348.                     }
  349.                 });
  350.             }
  351.         }
  352.  
  353.         return perm;
  354.     }
  355.  
  356.     function hasPermission(client, permission){
  357.         value = 0;
  358.         var perm = getPermissions(client);
  359.  
  360.         if(perm != "") {
  361.             permis = perm.split(",");
  362.             if(permis != null) {
  363.                 permis.forEach(function (per) {
  364.                     if (per == permission) value = 1;
  365.                 });
  366.             }
  367.         }
  368.  
  369.         return value;
  370.     }
  371.  
  372.     function isInBlockedChannel(client){
  373.         value = 0;
  374.  
  375.         if(config.blockedchannels != null){
  376.             config.blockedchannels.forEach(function(channel) {
  377.                 client.getChannels().forEach(function(chan) {
  378.                     if (channel.id == chan.id()) value = 1;
  379.                 });
  380.             });
  381.         }
  382.  
  383.         return value;
  384.     }
  385.  
  386.     function isABlockedChannel(channel){
  387.         value = 0;
  388.  
  389.         if(channel != null && config.blockedchannels != null){
  390.             config.blockedchannels.forEach(function(chan) {
  391.                 if (chan.id == channel.id()) value = 1;
  392.             });
  393.         }
  394.  
  395.         return value;
  396.     }
  397.  
  398.     function hasGroup(client, groupid){
  399.         var bool = 0;
  400.  
  401.         if(client != null){
  402.             client.getServerGroups().forEach(function(group) {
  403.                 if(group.id() == groupid)bool = 1;
  404.             });
  405.         }
  406.  
  407.         return bool;
  408.     }
  409.  
  410.     function callMenu(client){
  411.         var menu = getMenu(client);
  412.  
  413.         if(menu == -1){
  414.             resetMenu(client);
  415.         }
  416.         else if(config.autoSupports != null){
  417.             config.autoSupports.forEach(function(autoSup) {
  418.                 if(autoSup.supmenuid != null && autoSup.supmenuid == menu){
  419.                     if(autoSup.supchatmsg != "") client.chat(autoSup.supchatmsg);
  420.                     if(autoSup.supnewchannel != -1) client.moveTo(autoSup.supnewchannel);
  421.                 }
  422.             });
  423.         }
  424.     }
  425.    
  426.     function sendServerMessage(msg, poke){
  427.         backend.getClients().forEach(function(client) {
  428.             if(poke)client.poke(msg);
  429.             else client.chat(msg);
  430.         });
  431.     }
  432.    
  433.     function sendTeamMessage(msg, poke){
  434.         backend.getClients().forEach(function(client) {
  435.             if(isInAnyGroup(client) == 1){
  436.                 if(poke)client.poke(msg);
  437.                 else client.chat(msg);
  438.             }
  439.         });
  440.     }
  441.    
  442.     function sendOnlineInfo(client, username){
  443.         var bool = 0;
  444.         backend.getClients().forEach(function(user) {
  445.             if(user.description() == '('+username+') '){
  446.                 bool = 1;
  447.                 client.chat("[b][color=blue][Information][/color] Der Spieler "+getClickableName(user)+" ("+username+") befindet sich im [color=green]"+user.getChannels()[0].name()+"[/color][/b] ");
  448.             }
  449.         });
  450.         if(bool == 0){
  451.             client.chat("[b][color=blue][Information][/color] [color=red]Es ist kein Spieler mit dem Forumnamen ("+username+") online.[/color][/b] ");
  452.         }
  453.     }
  454.    
  455.  
  456.     function sendSecondChat(clientX){
  457.         backend.getChannels().forEach(function(channel){
  458.             if(isSupportUserChannel(channel) || isSupportGroupChannel(channel)) {
  459.  
  460.                 if (isSupportGroupChannel(channel) == 1) {
  461.                     channel.getClients().forEach(function (client) {
  462.                         value = ticketGet(client.uid());
  463.                         if (config.groups != null) {
  464.                             config.groups.forEach(function (group) {
  465.                                 if (group.channels != null && hasGroup(clientX, group.id) == 1) {
  466.                                     group.channels.forEach(function (cchannel) {
  467.                                         if (cchannel.id == channel.id() && cchannel.time <= value && getToga(clientX) == 1) clientX.chat(getSupportMessage(client, channel));
  468.                                     });
  469.                                 }
  470.                             });
  471.                         }
  472.                     });
  473.                 }
  474.  
  475.                 if (isSupportUserChannel(channel) == 1) {
  476.                     channel.getClients().forEach(function (client) {
  477.                         var value = ticketGet(client.uid());
  478.  
  479.                         if (config.users != null) {
  480.                             config.users.forEach(function (user) {
  481.                                 if (user.channels != null && user.uid == clientC.uid()) {
  482.                                     user.channels.forEach(function (cchannel) {
  483.                                        if (cchannel.id == channel.id() && cchannel.time <= value && getToga(clientX) == 1) clientX.chat(getSupportMessage(client, channel));
  484.                                     });
  485.                                 }
  486.                             });
  487.                         }
  488.                     });
  489.                 }
  490.             }
  491.         });
  492.     }
  493.  
  494.     setInterval(function() {
  495.         backend.getChannels().forEach(function(channel){
  496.             if(isSupportUserChannel(channel) || isSupportGroupChannel(channel)) {
  497.  
  498.                 if (isSupportGroupChannel(channel) == 1) {
  499.                     channel.getClients().forEach(function (client) {
  500.                         value = ticketAdd(client.uid());
  501.                         if (config.groups != null) {
  502.                             config.groups.forEach(function (group) {
  503.                                 if (group.channels != null) {
  504.                                     group.channels.forEach(function (cchannel) {
  505.                                         if (cchannel.id == channel.id() && cchannel.time == value) sendGroupMessage(group.id, getSupportMessage(client, channel));
  506.                                     });
  507.                                 }
  508.                             });
  509.                         }
  510.                     });
  511.                 }
  512.  
  513.                 if (isSupportUserChannel(channel) == 1) {
  514.                     var bool = isSupportGroupChannel(channel);
  515.                     channel.getClients().forEach(function (client) {
  516.                         var value = ticketGet(client.uid());
  517.                         if(bool == 0)value = ticketAdd(client.uid());
  518.  
  519.                         if (config.users != null) {
  520.                             config.users.forEach(function (user) {
  521.                                 if (user.channels != null) {
  522.                                     var sup = backend.getClientByUID(user.uid);
  523.                                     if(sup != null && getToga(sup) == 1 && !sup.isDeaf() && (isInBlockedChannel(sup) == 0 || getGamesupport(sup) == 1)) {
  524.                                         user.channels.forEach(function (cchannel) {
  525.                                             if (cchannel.id == channel.id() && cchannel.time == value) sup.chat(getSupportMessage(client, channel));
  526.                                         });
  527.                                     }
  528.                                 }
  529.                             });
  530.                         }
  531.                     });
  532.                 }
  533.             }
  534.         });
  535.     }, 60000);
  536.  
  537.     event.on('clientUndeaf', function(client) {
  538.         if(isInAnyGroup(client) == 1){
  539.             sendSecondChat(client);
  540.         }
  541.     });
  542.  
  543.     event.on('clientMove', function(ev) {
  544.         if(ev.invoker != null && isSupportLogChannel(ev.toChannel) == 1){
  545.             log(ev.fromChannel, ev.toChannel, ev.client, ev.invoker);
  546.         }
  547.  
  548.         if(isSupportGroupChannel(ev.toChannel) == 1 || isSupportUserChannel(ev.toChannel) == 1){
  549.            ticketReset(ev.client.uid());
  550.         }
  551.         else {
  552.             ticketUnset(ev.client.uid());
  553.         }
  554.  
  555.         if(isSupportInfoChannel(ev.toChannel) == 1){
  556.             if(config.infos != null){
  557.                 config.infos.forEach(function(info) {
  558.                     if(ev.toChannel.id() == info.id){
  559.                         if(info.type == 0)ev.client.poke(info.message);
  560.                         else if(info.type == 1)ev.client.chat(info.message);
  561.                     }
  562.                 });
  563.             }
  564.         }
  565.  
  566.         if(ev.fromChannel == null || isABlockedChannel(ev.fromChannel) == 1){
  567.             if(isInAnyGroup(ev.client)){
  568.                 if(ev.toChannel != null && isABlockedChannel(ev.toChannel) == 0){
  569.                     sendSecondChat(ev.client);
  570.                 }
  571.             }
  572.         }
  573.  
  574.         if(ev.toChannel != null && ev.toChannel.id() == config.supportWarteraum){
  575.             setMenu(ev.client, 1);
  576.             callMenu(ev.client);
  577.         }
  578.         else {
  579.             resetMenu(ev.client);
  580.         }
  581.     });
  582.  
  583.     event.on('chat', function(ev) {
  584.         if (!ev.client.isSelf()) {
  585.             var vars = ev.text.split(" ");
  586.             var cmd = vars[0];
  587.             var cmdmsg = "";
  588.             for(var i = 1; i < vars.length; i++){
  589.                 if(i != 1) cmdmsg += " ";
  590.                 cmdmsg += vars[i];
  591.             }
  592.  
  593.             if(ev.text == '!toga'){
  594.                 if(isInAnyGroup(ev.client) == 1){
  595.                     var value = toggleToga(ev.client);
  596.                     if(value == 0)ev.client.chat("[b][color=blue][Einstellungen][/color] Informationen: [color=red]deaktiviert[/color][/b]");
  597.                     else if(value == 1)ev.client.chat("[b][color=blue][Einstellungen][/color] Informationen: [color=green]aktiviert[/color][/b]");
  598.                 }
  599.             }
  600.             else if(ev.text == '!gamesupport'){
  601.                 if(isInAnyGroup(ev.client) == 1){
  602.                     var value = toggleGamesupport(ev.client);
  603.                     if(value == 0)ev.client.chat("[b][color=blue][Einstellungen][/color] GameSupport: [color=red]deaktiviert[/color][/b]");
  604.                     else if(value == 1)ev.client.chat("[b][color=blue][Einstellungen][/color] GameSupport: [color=green]aktiviert[/color][/b]");
  605.                 }
  606.             }
  607.             else if(ev.text == '!reload'){
  608.                 if(isInAnyGroup(ev.client) == 1){
  609.                     if(hasPermission(ev.client, "Reload")) {
  610.                         engine.reloadScripts();
  611.                         ev.client.chat("[b][color=blue][Info][/color] Du hast das Script [color=red]neugestartet[/color]![/b]");
  612.                     }
  613.                 }
  614.             }
  615.             else if(ev.text == '!getkeys'){
  616.                 if(isInAnyGroup(ev.client) == 1){
  617.                     if(hasPermission(ev.client, "Getkeys")) {
  618.                         var permissi = getPermissions(ev.client);
  619.                         if(permissi != ""){
  620.                             var permissions = permissi.split(",");
  621.                             var groups = "";
  622.                             permissions.forEach(function(permission) {
  623.                                 if(permission != null)groups = groups + ",'" + permission + "' ";
  624.                             });
  625.                             groups = "(" + groups.replace(",","") + ")";
  626.                             var sql = "SELECT * FROM view_infolog WHERE lastGroup IN " + groups + " ORDER BY lastDate DESC";
  627.  
  628.                             var permsk = hasPermission(ev.client, "GetAllKeys");
  629.                             if(permsk == 0)ev.client.chat("[b][color=blue][Info][/color] [color=red]last24h[/color] - [color=red]last7d[/color] - [color=green]Name[/color] - [color=purple]Gruppe[/color] - [color=gray]uid[/color][/b]");
  630.                             else ev.client.chat("[b][color=blue][Info][/color] [color=gray]lastDate[/color] - [color=red]last24h[/color] - [color=red]last7d[/color] - [color=red]lastMonth[/color] - [color=red]total[/color] - [color=green]Name[/color] - [color=purple]Gruppe[/color] - [color=gray]uid[/color][/b]");
  631.                             if (dbc) dbc.query(sql, function(err, res) {
  632.                                 if (!err) {
  633.                                     res.forEach(function(row) {
  634.                                         if(permsk == 0)ev.client.chat("[b][color=blue][Info][/color]  [color=red]" + helpers.toString(row.last24h) + "[/color] - [color=red]" + helpers.toString(row.last7d) + "[/color] - [color=green]" + helpers.toString(row.lastName) + "[/color] - [color=purple]" + helpers.toString(row.lastGroup) + "[/color] - [color=gray]" + helpers.toString(row.supporterUid) + "[/color][/b]");
  635.                                         else ev.client.chat("[b][color=blue][Info][/color]  [color=gray]" + helpers.toString(row.lastDate) + "[/color] - [color=red]" + helpers.toString(row.last24h) + "[/color] - [color=red]" + helpers.toString(row.last7d) + "[/color] - [color=red]" + helpers.toString(row.lastMonth) + "[/color] - [color=red]" + helpers.toString(row.total) + "[/color] - [color=green]" + helpers.toString(row.lastName) + "[/color] - [color=purple]" + helpers.toString(row.lastGroup) + "[/color] - [color=gray]" + helpers.toString(row.supporterUid) + "[/color][/b]");
  636.                                     });
  637.                                 }
  638.                             });
  639.                         }
  640.                     }
  641.                 }
  642.             }
  643.             else if(ev.text == '!resetoptions'){
  644.                 if(isInAnyGroup(ev.client) == 1){
  645.                     if(hasPermission(ev.client, "ResetOptions")) {
  646.                         store.getKeys().forEach(function(key) {
  647.                             store.unset(key);
  648.                         });
  649.                         ev.client.chat("[b][color=blue][Info][/color] Du hast alle Client-Einstellungen [color=red]zurückgesetzt[/color]![/b]");
  650.                     }
  651.                 }
  652.             }
  653.             else if(ev.text == '!help'){
  654.                 if(isInAnyGroup(ev.client) == 1){
  655.                     ev.client.chat("!help - zeigt diese List an");
  656.                     ev.client.chat("!toga - (de)aktiviert die Supportnachrichten");
  657.                     ev.client.chat("!gamesupport - (de)aktiviert die Supportnachrichten wenn man im Spiel ist. (Standartmäßig deaktiviert)");
  658.                     ev.client.chat("!getuser [Forumname] - Gibt den Spieler zurück, wenn er sich auf dem Teamspeak befindet");
  659.                     if(hasPermission(ev.client, "Getkeys")) {
  660.                         ev.client.chat("!getkeys - zeigt eine Liste der letzten Supporttätigkeiten eines Teammitgliedes");
  661.                     }
  662.                     if(hasPermission(ev.client, "Reload")) {
  663.                         ev.client.chat("!reload - lädt das Script neu (Notwendig, falls Beispielsweise keine Verbindung zur Datenbank besteht)");
  664.                     }
  665.                     if(hasPermission(ev.client, "ResetOptions")) {
  666.                         ev.client.chat("!resetoptions - schaltet bei allen Teammitgliedern wieder die Support-Benachrichtigungen an");
  667.                     }
  668.                     if(hasPermission(ev.client, "serverinfochat")) {
  669.                         ev.client.chat("!serverinfochat [Nachricht] - Schreibt alle Spieler auf den Server privat mit der [Nachricht] an");
  670.                     }
  671.                     if(hasPermission(ev.client, "serverinfopoke")) {
  672.                         ev.client.chat("!serverinfopoke [Nachricht] - Stubst alle Spieler auf den Server mit der [Nachricht] an");
  673.                     }
  674.                     if(hasPermission(ev.client, "teaminfochat")) {
  675.                         ev.client.chat("!teaminfochat [Nachricht] - Schreibt alle Teammitglieder auf den Server privat mit der [Nachricht] an");
  676.                     }
  677.                     if(hasPermission(ev.client, "teaminfopoke")) {
  678.                         ev.client.chat("!teaminfopoke [Nachricht] - Stubst alle Teammitglieder auf den Server mit der [Nachricht] an");
  679.                     }
  680.                 }
  681.             }
  682.             else if(cmd == "!serverinfochat"){
  683.                 if(isInAnyGroup(ev.client) == 1){
  684.                     if(hasPermission(ev.client, "serverinfochat")) {
  685.                         sendServerMessage(cmdmsg, false);
  686.                     }
  687.                 }
  688.             }
  689.             else if(cmd == "!serverinfopoke"){
  690.                 if(isInAnyGroup(ev.client) == 1){
  691.                     if(hasPermission(ev.client, "serverinfopoke")) {
  692.                         sendServerMessage(cmdmsg, true);
  693.                     }
  694.                 }
  695.             }
  696.             else if(cmd == "!teaminfochat"){
  697.                 if(isInAnyGroup(ev.client) == 1){
  698.                     if(hasPermission(ev.client, "teaminfochat")) {
  699.                         sendTeamMessage(cmdmsg, false);
  700.                     }
  701.                 }
  702.             }
  703.             else if(cmd == "!teaminfopoke"){
  704.                 if(isInAnyGroup(ev.client) == 1){
  705.                     if(hasPermission(ev.client, "teaminfopoke")) {
  706.                         sendTeamMessage(cmdmsg, true);
  707.                     }
  708.                 }
  709.             }
  710.             else if(cmd == "!getuser"){
  711.                 if(isInAnyGroup(ev.client) == 1){
  712.                     sendOnlineInfo(ev.client, cmdmsg);
  713.                 }
  714.             }
  715.             else {
  716.                 ev.client.getChannels().forEach(function (channel) {
  717.                     if (channel.id() == config.supportWarteraum) {
  718.                         var chatid = getMenu(ev.client);
  719.  
  720.                         if (config.autoSupports != null) {
  721.                             config.autoSupports.forEach(function (autoSup) {
  722.                                 if (chatid == autoSup.supmenuid) {
  723.                                     var bool = 0;
  724.                                     if(autoSup.awnsers != null){
  725.                                         autoSup.awnsers.forEach(function(awnser) {
  726.                                             if(awnser.value == ev.text){
  727.                                                 setMenu(ev.client, awnser.newmenuid);
  728.                                                 callMenu(ev.client);
  729.                                                 bool = 1;
  730.                                             }
  731.                                         });
  732.                                     }
  733.                                     if(bool == 0){
  734.                                         ev.client.chat("[b][color=darkred]Ungültige Eingabe![/color] Als Antwort wird eine Zahl erwartet![/b]");
  735.                                     }
  736.                                 }
  737.                             });
  738.                         }
  739.                     }
  740.                 });
  741.             }
  742.         }
  743.     });
  744. });
  745.  
  746. /*
  747.     ** VIEW INFOLOG **
  748.  
  749.    SELECT
  750.    (SELECT datum FROM log WHERE supporterUid = A1.supporterUid ORDER BY datum DESC LIMIT 1) AS lastDate,
  751.    (SELECT supporterName FROM log WHERE supporterUid = A1.supporterUid ORDER BY datum DESC LIMIT 1) AS lastName,
  752.    (SELECT configGroup FROM log WHERE supporterUid = A1.supporterUid ORDER BY datum DESC LIMIT 1) AS lastGroup,
  753.    (SELECT Count(*) FROM log WHERE supporterUid = A1.supporterUid AND TIMEDIFF(current_timestamp, datum) <= 240000 ORDER BY datum DESC LIMIT 1) AS last24h,
  754.    (SELECT Count(*) FROM log WHERE supporterUid = A1.supporterUid AND DATEDIFF(current_timestamp, datum) <= 7 ORDER BY datum DESC LIMIT 1) AS last7d,
  755.    (SELECT Count(*) FROM log WHERE supporterUid = A1.supporterUid AND DATEDIFF(current_timestamp, datum) <= 30 ORDER BY datum DESC LIMIT 1) AS lastMonth,
  756.    Count(*) AS total,
  757.    supporterUid
  758.    FROM `log` A1 WHERE 1 GROUP BY supporterUid ORDER BY datum DESC
  759.  
  760.  
  761.    ** VIEW GROUPINFO **
  762.  
  763.    SELECT
  764.      configGroup,
  765.      ROUND(100/(SELECT Count(*) FROM log WHERE TIMEDIFF(current_timestamp, datum) <= 240000)*(SELECT Count(*) FROM log WHERE TIMEDIFF(current_timestamp, datum) <= 240000 AND configGroup = A1.configGroup), 1) AS last24hProzent,
  766.      (SELECT Count(*) FROM log WHERE TIMEDIFF(current_timestamp, datum) <= 240000 AND configGroup = A1.configGroup) AS last24hCount,
  767.      (SELECT Count(*) FROM log WHERE TIMEDIFF(current_timestamp, datum) <= 240000) AS last24hCountAll,
  768.      ROUND(100/(SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 7)*(SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 7 AND configGroup = A1.configGroup), 1) AS last7dProzent,
  769.      (SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 7 AND configGroup = A1.configGroup) AS last7dCount,
  770.      (SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 7) AS last7dCountAll,
  771.      ROUND(100/(SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 30)*(SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 30 AND configGroup = A1.configGroup), 1) AS last30dProzent,
  772.      (SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 30 AND configGroup = A1.configGroup) AS last30dCount,
  773.      (SELECT Count(*) FROM log WHERE DATEDIFF(current_timestamp, datum) <= 30) AS last30dCountAll,
  774.      ROUND(100/(SELECT Count(*) FROM log)*Count(*), 1) AS totalProzent,
  775.      Count(*) AS totalCount,
  776.      (SELECT Count(*) FROM log) AS totalCountAll
  777.    FROM log A1 GROUP BY configGroup
  778.  
  779.  
  780.    ** VIEW GROUPCHANNELINFO **
  781.  
  782.    SELECT
  783.      fromChannelName,
  784.      configGroup,
  785.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000),1) AS last24hProzent,
  786.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000) AS last24hCount,
  787.      (SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000) AS last24hCountAll,
  788.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 7)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 7),1) AS last7dProzent,
  789.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 7) AS last7dCount,
  790.      (SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 7) AS last7dCountAll,
  791.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 30)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 30),1) AS last30dProzent,
  792.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 30) AS last30dCount,
  793.      (SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 30) AS last30dCountAll,
  794.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId)*Count(*),1) AS totalProzent,
  795.      Count(*) AS totalCount,
  796.      (SELECT Count(*) FROM log WHERE fromChannelId = A1.fromChannelId) AS totalCountAll
  797.  
  798.    FROM log A1 WHERE fromChannelId IN ('1387','1389','1386','1390','1991') GROUP BY configGroup,fromChannelId ORDER BY fromChannelName, configGroup
  799.  
  800.  
  801.  
  802.    ** VIEW USERCHANNELINFO **
  803.  
  804.    SELECT
  805.      supporterName,
  806.      configGroup,
  807.      fromChannelName,
  808.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000 AND supporterUid = A1.supporterUid)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000 AND supporterUid = A1.supporterUid),1) AS last24hProzent,
  809.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000 AND supporterUid = A1.supporterUid) AS last24hCount,
  810.      (SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND A1.fromChannelId AND TIMEDIFF(current_timestamp, datum) <= 240000 AND supporterUid = A1.supporterUid) AS last24hCountAll,
  811.  
  812.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND DATEDIFF(current_timestamp, datum) <= 7 AND supporterUid = A1.supporterUid)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 7 AND supporterUid = A1.supporterUid),1) AS last7dProzent,
  813.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 7 AND supporterUid = A1.supporterUid) AS last7dCount,
  814.      (SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND DATEDIFF(current_timestamp, datum) <= 7 AND supporterUid = A1.supporterUid) AS last7dCountAll,
  815.  
  816.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND DATEDIFF(current_timestamp, datum) <= 30 AND supporterUid = A1.supporterUid)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 30 AND supporterUid = A1.supporterUid),1) AS last30dProzent,
  817.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND DATEDIFF(current_timestamp, datum) <= 30 AND supporterUid = A1.supporterUid) AS last30dCount,
  818.      (SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND DATEDIFF(current_timestamp, datum) <= 30 AND supporterUid = A1.supporterUid) AS last30dCountAll,
  819.  
  820.      ROUND(100/(SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND supporterUid = A1.supporterUid)*(SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND supporterUid = A1.supporterUid),1) AS totalProzent,
  821.      (SELECT Count(*) FROM log WHERE configGroup = A1.configGroup AND fromChannelId = A1.fromChannelId AND supporterUid = A1.supporterUid) AS totalCount,
  822.      (SELECT Count(*) FROM log WHERE fromChannelId IN ('1387','1389','1386','1390','1991') AND supporterUid = A1.supporterUid) AS totalCountAll
  823.  
  824.    FROM log A1 WHERE fromChannelId IN ('1387','1389','1386','1390','1991') GROUP BY supporterUid,fromChannelId ORDER BY supporterUid,last24hProzent DESC
  825.  
  826.  
  827. */
Add Comment
Please, Sign In to add comment