thaldrin/src/utils/wrapper.features.ts

33 lines
826 B
TypeScript
Raw Normal View History

2021-04-07 00:14:41 +00:00
import sourcefinder from "./sourcefinder";
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
let SL = /(nosl|no-?short(link(s|ing)?)?)/gmi
let SF = /(nosf|no-?source(find(er|ing)?)?)/gmi
2021-04-07 14:51:51 +00:00
function disabled(message: Message, feature: string) {
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 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
export default async function Shortlink(message: Message, setting: boolean) {
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;
links.forEach(link => { return `<${link}>` })
return message.channel.send(links?.join("\n"))
2021-04-07 00:14:41 +00:00
}