change exception system
This commit is contained in:
parent
60234fce30
commit
66eda02578
@ -1,4 +1 @@
|
|||||||
LeinneSW
|
{"-1001197999963":[],"-1001147213930":[508945772,303980876],"-1001106315963":[56131694,508945772,263960906]}
|
||||||
kawaii_latina
|
|
||||||
Khinenw
|
|
||||||
psj1026
|
|
95
index.js
95
index.js
@ -2,57 +2,62 @@ const TelegramBot = require('node-telegram-bot-api')
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
const filter = require('./src/filter.js')
|
const filter = require('./src/filter.js')
|
||||||
const Sender = require('./src/sender.js')
|
const sender = require('./src/sender.js')
|
||||||
|
|
||||||
const commandManager = require('./src/commandManager.js')
|
const commandManager = require('./src/commandManager.js')
|
||||||
|
|
||||||
const bot_token = fs.readFileSync('./bot-token.txt', 'utf8')
|
const bot_token = fs.readFileSync('./bot-token.txt', 'utf8')
|
||||||
const bot = new TelegramBot(bot_token, { polling: true })
|
const bot = new TelegramBot(bot_token, { polling: true })
|
||||||
|
|
||||||
const sender = new Sender(bot)
|
const DEVELOPER = 121605312
|
||||||
|
|
||||||
let exception = [
|
let exception = {}
|
||||||
''
|
|
||||||
]
|
|
||||||
|
|
||||||
const command = new commandManager()
|
const command = new commandManager()
|
||||||
|
|
||||||
fs.readFile('./exception.txt', (err, data) => {
|
const syncException = (err, data) => {
|
||||||
if (err) {
|
if (err)
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
|
||||||
|
|
||||||
exception = []
|
try {
|
||||||
const line = (data + '').split('\r\n')
|
exception = JSON.parse(data)
|
||||||
for (const l of line) {
|
} catch (err) {
|
||||||
exception.push(l)
|
exception = {}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
fs.watch('./exception.txt', { encoding: 'buffer' }, (event, filename) => {
|
const init = () => {
|
||||||
if (filename) {
|
sender.init(bot)
|
||||||
fs.readFile('./exception.txt', (err, data) => {
|
fs.readFile('./exception.txt', syncException)
|
||||||
if (err) {
|
fs.watch('./exception.txt', { encoding: 'buffer' }, (event, filename) => {
|
||||||
console.log(err)
|
if (filename) {
|
||||||
}
|
fs.readFile('./exception.txt', syncException)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
exception = []
|
try {
|
||||||
const line = (data + '').split('\r\n')
|
init()
|
||||||
for (const l of line) {
|
} catch (err) {
|
||||||
exception.push(l)
|
fs.writeFile('./exception.txt', '{}', (err) => {
|
||||||
}
|
if (!err) {
|
||||||
})
|
init()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
bot.on('message', message => {
|
bot.on('message', message => {
|
||||||
const user = message.from.username
|
const user = message.from
|
||||||
const text = message.text
|
const text = message.text
|
||||||
const date = message.date
|
const date = message.date * 1000
|
||||||
|
|
||||||
if (!text || Number(new Date()) - date < 5000) {
|
if (!text || Math.abs(Date.now() - date) > 5000) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
if (user.id != DEVELOPER) {
|
||||||
|
return
|
||||||
|
}*/
|
||||||
|
|
||||||
if (text[0] === '/') {
|
if (text[0] === '/') {
|
||||||
let name = text.replace(/\//, '')
|
let name = text.replace(/\//, '')
|
||||||
@ -71,31 +76,39 @@ bot.on('message', message => {
|
|||||||
const c = command.getCommand(name)
|
const c = command.getCommand(name)
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'off':
|
case 'off':
|
||||||
c.execute(user, parameter).then(data => {
|
c.execute(message, parameter).then(data => {
|
||||||
sender.send(message.chat.id, data + '님이 사용을 중단하였습니다.', message.message_id)
|
sender.send(message.chat.id, data + '님이 사용을 하지 안심시오ㅠㅠㅠ', message.message_id)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
sender.send(message.chat.id, err + '님은 이미 사용 중단 중입니다.', message.message_id)
|
sender.send(message.chat.id, '않이~~ ' + err + '님은 이미 사용 중단 하셨슴시오 ㅡㅡ', message.message_id)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'on':
|
case 'on':
|
||||||
c.execute(user, parameter).then(data => {
|
c.execute(message, parameter).then(data => {
|
||||||
sender.send(message.chat.id, data + '님이 사용을 허가하였습니다.', message.message_id)
|
sender.send(message.chat.id, data + '님이 내 의지에 굴복하셧슴시오~~ 사용 허가 했심시오~~~', message.message_id)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
sender.send(message.chat.id, err + '님은 이미 사용중입니다.', message.message_id)
|
sender.send(message.chat.id, '호고곡~! ' + err + '님은 이미 사용중이심시오~~', message.message_id)
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'clear':
|
||||||
|
c.execute(message, parameter).then(data => {
|
||||||
|
sender.send(message.chat.id, '원격으로 목록을 지웠슴시오~~', message.message_id)
|
||||||
|
}).catch(err => {
|
||||||
|
sender.send(message.chat.id, '았~~!! ' + err + '님으 권한은 없는것 갓심시오~~', message.message_id)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'list':
|
case 'list':
|
||||||
c.execute(user, parameter).then(data => {
|
c.execute(message, parameter).then(data => {
|
||||||
sender.send(message.chat.id, data, message.message_id)
|
sender.send(message.chat.id, '졸본콘을 사용 않하는 나데기들임니다;;\n' + data, message.message_id)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
sender.send(message.chat.id, 'ERROR: ' + err, message.message_id)
|
sender.send(message.chat.id, '았~~!! ' + err + '님으 권한은 없는것 갓심시오~~', message.message_id)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const e of exception) {
|
const roomException = exception[message.chat.id]
|
||||||
if (user == e) {
|
if (roomException != undefined) {
|
||||||
|
if (roomException.includes(user.id)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
const commandAddException = require('./commands/commandAddException.js')
|
const commandAddException = require('./commands/commandAddException.js')
|
||||||
const commandRemoveException = require('./commands/commandRemoveException.js')
|
const commandRemoveException = require('./commands/commandRemoveException.js')
|
||||||
|
const commandClearException = require('./commands/commandClearException.js')
|
||||||
const commandListException = require('./commands/commandListException.js')
|
const commandListException = require('./commands/commandListException.js')
|
||||||
|
|
||||||
|
|
||||||
class command {
|
class command {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.commands = [
|
this.commands = [
|
||||||
new commandAddException(),
|
new commandAddException(),
|
||||||
new commandRemoveException(),
|
new commandRemoveException(),
|
||||||
|
new commandClearException(),
|
||||||
new commandListException()
|
new commandListException()
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ class command {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
execute (sender, parameter) {
|
execute (message, parameter) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,55 +5,40 @@ const command = require('./command.js')
|
|||||||
class commandAddException extends command {
|
class commandAddException extends command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('off', [
|
super('off', [
|
||||||
['string'],
|
|
||||||
[]
|
[]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(sender, parameter) {
|
execute(message, parameter) {
|
||||||
let target = null
|
|
||||||
|
|
||||||
let i = 0
|
|
||||||
for (const compare of this.parameter) {
|
|
||||||
const receive = parameter.map(e => {
|
|
||||||
return typeof e
|
|
||||||
})
|
|
||||||
|
|
||||||
if (compare.sort().toString() === receive.sort().toString()) {
|
|
||||||
switch(i) {
|
|
||||||
case 0:
|
|
||||||
target = parameter[0]
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
target = sender
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.readFile('./exception.txt', (err, data) => {
|
fs.readFile('./exception.txt', (err, data) => {
|
||||||
if (err) {
|
if (err)
|
||||||
reject(err)
|
reject(err)
|
||||||
|
|
||||||
|
let json = {}
|
||||||
|
let list = []
|
||||||
|
try {
|
||||||
|
json = JSON.parse(data)
|
||||||
|
list = json[message.chat.id]
|
||||||
|
} catch (err) {}
|
||||||
|
|
||||||
|
if (list === undefined) {
|
||||||
|
list = []
|
||||||
}
|
}
|
||||||
|
|
||||||
const line = (data + '').split('\r\n')
|
if (!list.includes(message.from.id)) {
|
||||||
for (const l of line) {
|
list.push(message.from.id)
|
||||||
if (l == target) {
|
json[message.chat.id] = list
|
||||||
reject(target)
|
|
||||||
|
|
||||||
return
|
fs.writeFile('./exception.txt', JSON.stringify(json), err => {
|
||||||
}
|
if (err)
|
||||||
|
reject(err)
|
||||||
|
|
||||||
|
resolve(message.from.first_name)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
reject(message.from.first_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFile('./exception.txt', data + target + '\r\n', err => {
|
|
||||||
if (err)
|
|
||||||
reject(err)
|
|
||||||
|
|
||||||
resolve(target)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
30
src/commands/commandClearException.js
Normal file
30
src/commands/commandClearException.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
const command = require('./command.js')
|
||||||
|
|
||||||
|
const DEVELOPER = 121605312
|
||||||
|
|
||||||
|
class commandClearException extends command {
|
||||||
|
constructor() {
|
||||||
|
super('clear', [
|
||||||
|
[]
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(message, parameter) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (message.from.id == DEVELOPER) {
|
||||||
|
fs.writeFile('./exception.txt', '{}', err => {
|
||||||
|
if (err)
|
||||||
|
reject(err)
|
||||||
|
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
reject(message.from.first_name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = commandClearException
|
@ -1,27 +1,56 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
const command = require('./command.js')
|
const command = require('./command.js')
|
||||||
|
const sender = require('../sender.js')
|
||||||
|
|
||||||
|
const DEVELOPER = 121605312
|
||||||
|
|
||||||
class commandListException extends command {
|
class commandListException extends command {
|
||||||
constructor () {
|
constructor() {
|
||||||
super('list', [
|
super('list', [
|
||||||
[],
|
[]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
execute (sender, parameter) {
|
execute(message, parameter) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.readFile('./exception.txt', (err, data) => {
|
if (message.from.id == DEVELOPER) {
|
||||||
if (err) {
|
fs.readFile('./exception.txt', (err, data) => {
|
||||||
console.log(err)
|
if (err)
|
||||||
}
|
reject(err)
|
||||||
|
|
||||||
if (data == '') {
|
let json = {}
|
||||||
resolve('예외 목록이 없습니다.')
|
let list = []
|
||||||
} else {
|
let result = []
|
||||||
resolve('예외 목록:\n' + data)
|
try {
|
||||||
}
|
json = JSON.parse(data)
|
||||||
})
|
list = json[message.chat.id]
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list == undefined) {
|
||||||
|
resolve('사실 아무도 엄스심시~~')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
; (async () => {
|
||||||
|
if (list.length === 0) {
|
||||||
|
resolve('사실 아무도 엄스심시~~')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const id of list) {
|
||||||
|
const chatUser = await sender.bot.getChatMember(message.chat.id, id)
|
||||||
|
result.push(chatUser.user.first_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(result.join('\n'))
|
||||||
|
})()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
reject(message.from.first_name)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,67 +3,42 @@ const fs = require('fs')
|
|||||||
const command = require('./command.js')
|
const command = require('./command.js')
|
||||||
|
|
||||||
class commandRemoveException extends command {
|
class commandRemoveException extends command {
|
||||||
constructor () {
|
constructor() {
|
||||||
super('on', [
|
super('on', [
|
||||||
['string'],
|
|
||||||
[]
|
[]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
execute (sender, parameter) {
|
execute(message, parameter) {
|
||||||
let target = null
|
|
||||||
|
|
||||||
let i = 0
|
|
||||||
for (const compare of this.parameter) {
|
|
||||||
const receive = parameter.map(e => {
|
|
||||||
return typeof e
|
|
||||||
})
|
|
||||||
|
|
||||||
if (compare.sort().toString() === receive.sort().toString()) {
|
|
||||||
switch(i) {
|
|
||||||
case 0:
|
|
||||||
target = parameter[0]
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
target = sender
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.readFile('./exception.txt', (err, data) => {
|
fs.readFile('./exception.txt', (err, data) => {
|
||||||
if (err)
|
if (err)
|
||||||
reject(err)
|
reject(err)
|
||||||
|
|
||||||
const line = (data + '').split('\r\n')
|
try {
|
||||||
let list = ''
|
let json = JSON.parse(data)
|
||||||
let checker = false
|
let list = json[message.chat.id]
|
||||||
|
|
||||||
for (const l of line) {
|
if (list.includes(message.from.id)) {
|
||||||
if (l == target) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
checker = true
|
if (list[i] == message.from.id) {
|
||||||
continue
|
list.splice(i, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
json[message.chat.id] = list
|
||||||
|
|
||||||
|
fs.writeFile('./exception.txt', JSON.stringify(json), err => {
|
||||||
|
if (err)
|
||||||
|
reject(err)
|
||||||
|
|
||||||
|
resolve(message.from.first_name)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
reject(message.from.first_name)
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
if (l == '') {
|
reject(message.from.first_name)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
list += l + '\r\n'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checker) {
|
|
||||||
fs.writeFile('./exception.txt', list, err => {
|
|
||||||
if (err)
|
|
||||||
reject(err)
|
|
||||||
|
|
||||||
resolve(target)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
reject(target)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -77,12 +77,14 @@ function getSticker (text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bot = null
|
||||||
|
|
||||||
class sender {
|
class sender {
|
||||||
constructor (bot) {
|
static init (bot_) {
|
||||||
this.bot = bot
|
bot = bot_
|
||||||
}
|
}
|
||||||
|
|
||||||
sendSticker(id, text, reply) {
|
static sendSticker(id, text, reply) {
|
||||||
if (text.indexOf(' ') != -1) {
|
if (text.indexOf(' ') != -1) {
|
||||||
const phrase = text.split(' ')
|
const phrase = text.split(' ')
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ class sender {
|
|||||||
const sticker = getSticker(p)
|
const sticker = getSticker(p)
|
||||||
|
|
||||||
if (sticker) {
|
if (sticker) {
|
||||||
this.bot.sendSticker(id, sticker, {
|
bot.sendSticker(id, sticker, {
|
||||||
reply_to_message_id: reply
|
reply_to_message_id: reply
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -99,18 +101,22 @@ class sender {
|
|||||||
const sticker = getSticker(text)
|
const sticker = getSticker(text)
|
||||||
|
|
||||||
if (sticker) {
|
if (sticker) {
|
||||||
this.bot.sendSticker(id, sticker, {
|
bot.sendSticker(id, sticker, {
|
||||||
reply_to_message_id: reply
|
reply_to_message_id: reply
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
send(id, text, reply) {
|
static send(id, text, reply) {
|
||||||
this.bot.sendMessage(id, text, {
|
bot.sendMessage(id, text, {
|
||||||
reply_to_message_id: reply
|
reply_to_message_id: reply
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get bot () {
|
||||||
|
return bot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = sender
|
module.exports = sender
|
Loading…
Reference in New Issue
Block a user