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