rework command system

master
Semisol 2021-09-04 16:21:12 +03:00
parent 9bab1d3600
commit 2759f0d96f
Signed by: Semisol
GPG Key ID: D1C04206D89306D5
1 changed files with 86 additions and 52 deletions

138
index.js
View File

@ -34,9 +34,9 @@ let globCd = 0
let wallops = []
let joins = []
if (!fs.existsSync("log.txt")) fs.writeFileSync("log.txt", "")
let log = fs.readFileSync("log.txt").toString().split("\n").filter(x=>x)
let log = fs.readFileSync("log.txt").toString().split("\n").filter(x => x)
let lockActive = false
function logS(str){
function logS(str) {
let d = new Date()
log.push(`[${d.getUTCDate().toString().padStart(2, "0")}/${d.getUTCMonth().toString().padStart(2, "0")} ${d.getUTCHours().toString().padStart(2, "0")}:${d.getUTCMinutes().toString().padStart(2, "0")}:${d.getUTCSeconds().toString().padStart(2, "0")}] ${str}`)
if (log.length > conf.logLength) log.shift()
@ -101,45 +101,79 @@ bot.on("wallops", (wallop) => {
}
})
bot.on("privmsg", (e) => {
if (e.target === conf.user.nick){
if (e.target === conf.user.nick) {
bot.notice(e.nick, bold + "+--------------- WallopsServ ---------------+")
bot.notice(e.nick, "" + "| WallopsServ provides a channel to send |")
bot.notice(e.nick, "" + "| and receive wallops. The prefix "+conf.prefix+" can be |")
bot.notice(e.nick, "" + "| used in the channel to send one. |")
bot.notice(e.nick, "" + "| Channel: " + conf.channel.padEnd(31, " ") +" |")
bot.notice(e.nick, "" + "| WallopsServ provides a channel to send |")
bot.notice(e.nick, "" + "| and receive wallops. The prefix " + conf.prefix + " can be |")
bot.notice(e.nick, "" + "| used in the channel to send one. |")
bot.notice(e.nick, "" + "| Channel: " + conf.channel.padEnd(31, " ") + " |")
bot.notice(e.nick, bold + "+--------------- WallopsServ ---------------+")
return
}
if (e.target === conf.channel && e.message === conf.cmdPrefix + "sendlog" && admin.includes(genIdentity2(e))){
logS(genIdentity2(e) + " requested the log")
transporter.sendMail({
from: conf.mail.sender,
to: conf.mail.receiver,
subject: "Log request",
text: "The log is attached to this message.",
attachments: [
{
filename: "log.txt",
contentDisposition: "inline",
content: log.join("\n"),
contentType: "text/plain"
}
]
})
bot.notice(conf.channel, "Log sent.")
if (e.target === conf.channel && admin.includes(genIdentity2(e)) && e.message.startsWith(conf.cmdPrefix)) {
let args = e.message.slice(conf.cmdPrefix.length).split(" ")
let cmd = args.shift()
switch (cmd) {
case "rehash":
logS(genIdentity2(e) + " rehashed the config")
conf = JSON.parse(fs.readFileSync("wallopsserv.json"))
map = conf.relays
exemptUsers = conf.cooldownExempt
admin = conf.admin
map2 = conf.shortMap
bot.notice(conf.channel, "Rehashed.")
break
case "sendlog":
logS(genIdentity2(e) + " requested the log")
transporter.sendMail({
from: conf.mail.sender,
to: conf.mail.receiver,
subject: "Log request",
text: "The log is attached to this message.",
attachments: [
{
filename: "log.txt",
contentDisposition: "inline",
content: log.join("\n"),
contentType: "text/plain"
}
]
})
bot.notice(conf.channel, "Log sent.")
break
case "forcelock":
if (args.length < 1) return bot.say(conf.channel, "No type specified")
if (args[0] !== "i" && args[0] !== "m") return bot.say(conf.channel, "Invalid lock type")
logS("Channel locked: spam")
lockActive = true
bot.say(conf.channel, bold + "Locking channel for 60 seconds")
bot.mode(conf.channel, "+" + args[0])
bot.raw("locops", "#wallops has been locked due to request")
transporter.sendMail({
from: conf.mail.sender,
to: conf.mail.receiver,
subject: "#wallops has been locked (on demand)",
text: "#wallops has been locked via the request of " + genIdentity2(e) + " with mode +" + args[0] + ".\nA log has been attached.",
attachments: [
{
filename: "log.txt",
contentDisposition: "inline",
content: log.join("\n"),
contentType: "text/plain"
}
]
})
setTimeout(() => {
lockActive = false
bot.say(conf.channel, bold + "Channel unlocked")
bot.mode(conf.channel, "-" + args[0])
logS("Channel unlocked")
}, 60000)
break
}
return
}
if (e.target === conf.channel && e.message === conf.cmdPrefix + "rehash" && admin.includes(genIdentity2(e))){
logS(genIdentity2(e) + " rehashed the config")
conf = JSON.parse(fs.readFileSync("wallopsserv.json"))
map = conf.relays
exemptUsers = conf.cooldownExempt
admin = conf.admin
map2 = conf.shortMap
bot.notice(conf.channel, "Rehashed.")
return
}
if (e.target === conf.channel && e.message === conf.cmdPrefix + "hostmask"){
if (e.target === conf.channel && e.message === conf.cmdPrefix + "hostmask") {
bot.say(conf.channel, "Your hostmask is: " + genIdentity2(e))
return
}
@ -149,12 +183,12 @@ bot.on("privmsg", (e) => {
bot.say(conf.channel, `${e.nick}: Message too long`)
return
}
if (!exemptUsers.includes(genIdentity2(e))){
if (cd[e.nick.toLowerCase()] > Date.now()){
if (!exemptUsers.includes(genIdentity2(e))) {
if (cd[e.nick.toLowerCase()] > Date.now()) {
bot.say(conf.channel, `${e.nick}: Whow, slow down there! (${bold}${((cd[e.nick.toLowerCase()] - Date.now()) / 1000).toFixed(1)}s${reset})`)
return
}
if (globCd > Date.now()){
if (globCd > Date.now()) {
bot.say(conf.channel, `${e.nick}: Whow, slow down there! (${bold}${((globCd - Date.now()) / 1000).toFixed(1)}s${reset} channel)`)
return
}
@ -163,10 +197,10 @@ bot.on("privmsg", (e) => {
}
bot.raw(`wallops :${genIdentity(e)} ${reset}${e.message.slice(1)}`)
logS(genIdentity2(e) + ` (${e.tags["unrealircd.org/userip"] || "???"})` + ": " + e.message.slice(1))
if (!exemptUsers.includes(genIdentity2(e))){
if (!exemptUsers.includes(genIdentity2(e))) {
wallops.push(Date.now() + 60000)
wallops = wallops.filter(l => l > Date.now())
if (wallops.length > 9 && !lockActive){
if (wallops.length > 9 && !lockActive) {
logS("Channel locked: spam")
lockActive = true
bot.say(conf.channel, bold + "Locking channel for 30 seconds")
@ -186,7 +220,7 @@ bot.on("privmsg", (e) => {
}
]
})
setTimeout(()=>{
setTimeout(() => {
lockActive = false
bot.say(conf.channel, bold + "Channel unlocked")
bot.mode(conf.channel, "-m")
@ -196,14 +230,14 @@ bot.on("privmsg", (e) => {
}
}
});
bot.on("join", (evt)=>{
bot.on("join", (evt) => {
if (evt.channel !== conf.channel || evt.nick === conf.user.nick) return
logS(`${evt.nick}!${evt.ident}@${evt.hostname}${evt.gecos?`#${evt.gecos}`:""} (${evt.tags["unrealircd.org/userip"] || "???"}) joins`)
logS(`${evt.nick}!${evt.ident}@${evt.hostname}${evt.gecos ? `#${evt.gecos}` : ""} (${evt.tags["unrealircd.org/userip"] || "???"}) joins`)
if (evt.nick.includes("/")) return
joins = joins.filter(l => l[0] !== evt.nick.toLowerCase())
joins.push([evt.nick.toLowerCase(), Date.now() + 60000])
joins = joins.filter(l => l[1] > Date.now())
if (joins.length > 5 && !lockActive){
if (joins.length > 5 && !lockActive) {
logS("Channel locked: too many joins")
lockActive = true
bot.say(conf.channel, bold + "Locking channel for 60 seconds")
@ -223,7 +257,7 @@ bot.on("join", (evt)=>{
}
]
})
setTimeout(()=>{
setTimeout(() => {
lockActive = false
bot.say(conf.channel, bold + "Channel unlocked")
bot.mode(conf.channel, "-i")
@ -231,13 +265,13 @@ bot.on("join", (evt)=>{
}, 60000)
}
})
bot.on("part", (evt)=>{
bot.on("part", (evt) => {
if (evt.nick === conf.user.nick) return
logS(`${evt.nick}!${evt.ident}@${evt.hostname}${evt.gecos?`#${evt.gecos}`:""} (${evt.tags["unrealircd.org/userip"] || "???"}) parts`)
logS(`${evt.nick}!${evt.ident}@${evt.hostname}${evt.gecos ? `#${evt.gecos}` : ""} (${evt.tags["unrealircd.org/userip"] || "???"}) parts`)
})
bot.on("quit", (evt)=>{
bot.on("quit", (evt) => {
if (evt.nick === conf.user.nick) return
logS(`${evt.nick}!${evt.ident}@${evt.hostname}${evt.gecos?`#${evt.gecos}`:""} (${evt.tags["unrealircd.org/userip"] || "???"}) quits`)
logS(`${evt.nick}!${evt.ident}@${evt.hostname}${evt.gecos ? `#${evt.gecos}` : ""} (${evt.tags["unrealircd.org/userip"] || "???"}) quits`)
})
bot.on("kick", (e) => {
if (e.kicked === conf.user.nick && e.channel === conf.channel) {
@ -245,17 +279,17 @@ bot.on("kick", (e) => {
bot.raw(`kill ${e.nick} :Go away and don't disturb me (kicked WallopsServ from ${conf.channel})`);
}
});
bot.on("raw", (s)=>{
bot.on("raw", (s) => {
if (!s.from_server) return
if (!s.line.endsWith("\r\n")) return
let r = s.line.slice(0, -2).split(" ")
if (r[0].startsWith(":") && r[1] === "KILL" && r[2].toLowerCase() === conf.user.nick){
if (r[0].startsWith(":") && r[1] === "KILL" && r[2].toLowerCase() === conf.user.nick) {
logS("Killed by " + r[0].slice(1))
transporter.sendMail({
from: conf.mail.sender,
to: conf.mail.receiver,
subject: "Bot killed",
text: "The bot has been killed by "+r[0].slice(1)+"\nA log has been attached.",
text: "The bot has been killed by " + r[0].slice(1) + "\nA log has been attached.",
attachments: [
{
filename: "log.txt",