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