registerPlugin({
name: 'Montys Move Request',
version: '0.1.0',
description: 'Move Request Test',
author: 'Montary',
vars: [
{
name: 'ShowLog',
indent: 1,
title: 'Show Logs?',
type: 'select',
options: ['NO','YES']
},
{
name: 'MoveRequestPermissionGroupId',
indent: 1,
title: 'MoveRequestPermissionGroupId',
type: 'number'
},{
name: "MsgRequest",
title: "MsgRequest placeholder : [clientname]",
indent: 1,
type: "string"
},{
name: "MsgRequestFailed",
title: "MsgRequestFailed",
indent: 1,
type: "string"
},{
name: "MsgRequestRefused",
title: "MsgRequestRefused",
indent: 1,
type: "string"
},{
name: "MsgRequestSended",
title: "MsgRequestSended",
indent: 1,
type: "string"
}
]
}, (_, config, meta) => {
const engine = require('engine');
const backend = require('backend');
const store = require('store');
const event = require('event');
//setting var
var MoveRequestPermissionGroupId = config.MoveRequestPermissionGroupId;
var ShowLog = config.ShowLog;
var MsgRequest = config.MsgRequest;
var MsgRequestFailed = config.MsgRequestFailed;
var MsgRequestSended = config.MsgRequestSended;
var MsgRequestRefused = config.MsgRequestRefused;
event.on('chat', function(ev) {
var Message = ev.text;
var Client = ev.client;
var ClientGroups = Client.getServerGroups();
if(Client.isSelf()){
return;
}
for(var i = 0; i< ClientGroups.length;i++){
if(Message.includes("!switchto=")){
if(ClientGroups[i].id()==config.MoveRequestPermissionGroupId){
//right permission
if(ShowLog){engine.log("nickname = "+Message.substring(10,Message.length));}
var AskClient = backend.getClientByName(Message.substring(10,Message.length));
if(AskClient === undefined){
Client.chat(MsgRequestFailed);
if(ShowLog){engine.log("Message send to "+Client.name()+" "+MsgRequestFailed);}
return;
}
if(ShowLog){engine.log(AskClient);}
store.set(AskClient.uid()+"MoveRequest",Client.uid());
Client.chat(MsgRequestSended);
if(ShowLog){engine.log("Message send to "+Client.name()+" "+MsgRequestSended);}
AskClient.chat(MsgRequest.replace("[clientname]",Client.name()));
if(ShowLog){engine.log("Message send to "+AskClient.name()+" "+MsgRequest);}
return;
}
}
}
if(store.get(Client.uid()+"MoveRequest")!= 'undefined'){
for(var i = 0; i< ClientGroups.length;i++){
if(Message == "yes"){
var ReqClient = backend.getClientByUniqueID(store.get(Client.uid()+"MoveRequest"));
var Channels = Client.getChannels();
ReqClient.moveTo(Channels[0].id());
if(ShowLog){engine.log("Switch Client "+ReqClient.name()+" to "+Channels[0].name());}
store.unset(Client.uid()+"MoveRequest");
}else if(Message == "no"){
var ReqClient = backend.getClientByUniqueID(store.get(Client.uid()+"MoveRequest"));
ReqClient.chat(MsgRequestRefused);
store.unset(Client.uid()+"MoveRequest");
if(ShowLog){engine.log("Message send to "+ReqClient.name()+" "+MsgRequestRefused);}
}
}
}
});
});