2021-04-07 18:14:24 +00:00
|
|
|
import Sourcefinder from "@thaldrin/sourcefinder";
|
2021-07-02 09:28:36 +00:00
|
|
|
// import Sourcefinder from "../../../sourcefinder/build/index";
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 18:14:24 +00:00
|
|
|
import config from "../../config";
|
2021-04-07 00:14:41 +00:00
|
|
|
import shortlink from "./shortlink";
|
2021-04-07 14:51:51 +00:00
|
|
|
import { Message, TextChannel } from "discord.js";
|
2021-04-07 00:14:41 +00:00
|
|
|
|
|
|
|
|
2021-04-07 18:14:24 +00:00
|
|
|
const sourcefinder = new Sourcefinder(`Thaldrin/v${config.pkg.version} (t8.pm/bot)`)
|
|
|
|
|
2021-04-07 00:14:41 +00:00
|
|
|
let SL = /(nosl|no-?short(link(s|ing)?)?)/gmi
|
|
|
|
let SF = /(nosf|no-?source(find(er|ing)?)?)/gmi
|
2021-04-08 00:10:37 +00:00
|
|
|
let CMD = /(nocmd|no-?command(s)?)/gmi
|
2021-04-07 00:14:41 +00:00
|
|
|
|
2021-04-08 00:10:37 +00:00
|
|
|
function disabled(message: Message, feature: "sf" | "sl" | "cmd") {
|
2021-04-07 14:51:51 +00:00
|
|
|
|
2021-04-07 11:19:23 +00:00
|
|
|
switch (feature) {
|
|
|
|
case 'sl':
|
2021-04-07 14:51:51 +00:00
|
|
|
// @ts-ignore
|
|
|
|
return SL.test((message.channel as TextChannel).topic)
|
2021-04-07 18:14:24 +00:00
|
|
|
case 'sf':
|
|
|
|
// @ts-ignore
|
|
|
|
return SF.test((message.channel as TextChannel).topic)
|
2021-04-08 00:10:37 +00:00
|
|
|
case 'cmd':
|
|
|
|
// @ts-ignore
|
|
|
|
return CMD.test((message.channel as TextChannel).topic)
|
2021-04-07 11:19:23 +00:00
|
|
|
|
|
|
|
default:
|
2021-04-07 14:51:51 +00:00
|
|
|
throw new Error("No Feature was defined.")
|
2021-04-07 11:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-07 00:14:41 +00:00
|
|
|
|
2021-04-07 18:14:24 +00:00
|
|
|
export async function Shortlink(message: Message, setting: boolean) {
|
2021-04-07 00:14:41 +00:00
|
|
|
if (!setting) return;
|
2021-04-07 14:51:51 +00:00
|
|
|
if (disabled(message, 'sl')) return;
|
|
|
|
let links = await shortlink(message.content)
|
|
|
|
|
|
|
|
if (!links) return;
|
|
|
|
return message.channel.send(links?.join("\n"))
|
2021-04-07 00:14:41 +00:00
|
|
|
|
2021-04-07 18:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function SourceFinder(message: Message, setting: boolean) {
|
|
|
|
if (!setting) return;
|
|
|
|
if (disabled(message, 'sf')) return;
|
|
|
|
let sources = await sourcefinder.find(message.content)
|
2021-04-07 19:22:12 +00:00
|
|
|
if (!sources) return;
|
|
|
|
return message.channel.send(sources?.join('\n'))
|
2021-04-08 00:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function Commands(message: Message) {
|
|
|
|
return disabled(message, "cmd")
|
2021-04-07 00:14:41 +00:00
|
|
|
}
|