Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const VoteKick = module.exports = {
- command: '!votekick',
- active: {}
- }
- VoteKick.manager = function * (message, command) {
- if (!(message.sender in VoteKick.active))
- VoteKick.active[message.sender] = {}
- const parsed = VoteKick.parser(command)
- const issuer = yield global.NameCache.get(message.from)
- const target = yield global.NameCache.get(parsed.target)
- if (parsed.vote !== undefined)
- VoteKick.voteUser(message.sender, issuer, target, parsed.vote)
- else
- VoteKick.createVote(message.sender, issuer, target)
- }
- VoteKick.createVote = function (conference, issuer, target) {
- if (target.id in VoteKick.active[conference])
- return global.VK.api.messages.send({
- peer_id: conference,
- message: `Голосование за исключение [id${target.id}|${target.first_name} ${target.last_name}] уже началось`
- })
- VoteKick.active[conference][target.id] = {yes: [issuer.id], no: []}
- global.VK.api.messages.send({
- peer_id: conference,
- message: `[id${issuer.id}|${issuer.first_name} ${issuer.last_name}] начал голосование за исключение [id${target.id}|${target.first_name} ${target.last_name}]
- Проголосуйте с помощью ${VoteKick.command} @id${target.id} yes/no`
- })
- }
- VoteKick.voteUser = function (conference, issuer, target, vote = false) {
- if (!(target.id in VoteKick.active[conference]))
- return global.VK.api.messages.send({
- peer_id: conference,
- message: `Голосование за исключение [id${target.id}|${target.first_name} ${target.last_name}] не начиналось`
- })
- if (VoteKick.active[conference][target.id]['yes'].includes(issuer.id))
- return global.VK.api.messages.send({
- peer_id: conference,
- message: `Вы уже проголосовали за исключение [id${target.id}|${target.first_name} ${target.last_name}]`
- })
- if (VoteKick.active[conference][target.id]['yes'].includes(issuer.id))
- return global.VK.api.messages.send({
- peer_id: conference,
- message: `Вы уже проголосовали против исключения [id${target.id}|${target.first_name} ${target.last_name}]`
- })
- if (vote) {
- VoteKick.active[conference][target.id]['yes'].push(issuer.id)
- return global.VK.api.messages.send({
- peer_id: conference,
- message: `За исключение [id${target.id}|${target.first_name} ${target.last_name}] проголосовало ${VoteKick.active[target.id].yes.length} из 15 человек`
- })
- } else {
- VoteKick.active[conference][target.id]['no'].push(issuer.id)
- return global.VK.api.messages.send({
- peer_id: conference,
- message: `Против исключения [id${target.id}|${target.first_name} ${target.last_name}] проголосовало ${VoteKick.active[target.id].no.length} из 15 человек`
- })
- }
- }
- VoteKick.parser = function (command) {
- let toRet = {}
- if (command[0] != VoteKick.command)
- return false
- if (command[1] === undefined)
- return false
- const regexp = command[1].match(/\[id(\d+)\|.+\]/)
- if (regexp === null || regexp[1] === undefined)
- return false
- toRet["target"] = regexp[1]
- if (command[2] !== undefined) {
- if (command[2] == 'yes')
- toRet["vote"] = true
- if (command[2] == 'no')
- toRet["vote"] = false
- }
- return toRet
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement