registerPlugin({
name: 'Montys Captcha Code',
version: '0.1.0',
description: 'Captcha Test',
author: 'Montary',
vars: [
{
name: 'ShowLog',
indent: 1,
title: 'Show Logs?',
type: 'select',
options: ['NO','YES']
},
{
name: 'AffectedGroupId',
indent: 1,
title: 'The group who use the script',
type: 'number'
},{
name: "MsgVerification",
title: "The verification message [quest] displays the math quest",
indent: 1,
type: "string"
},{
name: "MsgWrongAnswer",
title: "MsgWrongAnswer",
indent: 1,
type: "string"
},{
name: "MsgRightAnswer",
title: "MsgRightAnswer",
indent: 1,
type: "string"
},{
name: "StickyGroupId",
title: "StickyGroupId",
indent: 1,
type: "number"
}
]
}, (_, config, meta) => {
const engine = require('engine');
const store = require('store');
const event = require('event');
//setting var
var AffectedGroups = config.AffectedGroups;
var ShowLog = config.ShowLog;
var MsgWrongAnswer = config.MsgWrongAnswer;
var MsgRightAnswer = config.MsgRightAnswer;
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(ClientGroups[i].id()==config.AffectedGroupId){
if(ShowLog){engine.log('Got message "'+ Message +'" from '+ Client.name());}
if(Message == store.get(Client.uid()+"Sum")){
store.unset(Client.uid()+"Sum");
Client.removeFromServerGroup(config.StickyGroupId);
Client.chat(MsgRightAnswer);
}else{
Client.chat(MsgWrongAnswer);
}
}
}
});
event.on('clientMove', function(cm) {
var Client = cm.client;
var FromChannel = cm.fromChannel;
var ClientGroups = Client.getServerGroups();
if (typeof FromChannel == 'undefined' || FromChannel == '') {
//joined
for(var i = 0; i< ClientGroups.length;i++){
if(ClientGroups[i].id()==config.AffectedGroupId){
Client.addToServerGroup(config.StickyGroupId);
var random1 = Math.floor(Math.random() * Math.floor(20));
var random2 = Math.floor(Math.random() * Math.floor(20));
var opterator = "";
var rndOpterator = Math.floor(Math.random() * Math.floor(4));
if(rndOpterator == 0){
opterator = "+";
store.set(Client.uid()+"Sum",""+(random1+random2));
}else if(rndOpterator == 1){
opterator = "-";
store.set(Client.uid()+"Sum",""+(random1-random2));
}else if(rndOpterator == 2){
opterator = "*";
store.set(Client.uid()+"Sum",""+(random1*random2));
}else if(rndOpterator == 3){
opterator = "/";
store.set(Client.uid()+"Sum",""+(random1/random2));
}
var textAnswer = ""+random1+opterator+random2;
Client.chat(config.MsgVerification.replace("[quest]",textAnswer));
}
}
}
});
});