mirror of https://github.com/thaldrin/thaldrin.git
make Shortlink feature work properly
This commit is contained in:
parent
f2aa391651
commit
16e911c7a1
|
@ -11,7 +11,7 @@
|
|||
"@supabase/supabase-js": "^1.7.7",
|
||||
"@thaldrin/sourcefinder": "^1.0.0",
|
||||
"chalk": "^4.1.0",
|
||||
"discord.js": "^12.5.1",
|
||||
"discord.js": "^12.5.3",
|
||||
"winston": "^3.3.3",
|
||||
"winston-daily-rotate-file": "^4.5.1",
|
||||
"yiff": "^3.0.3"
|
||||
|
@ -310,18 +310,18 @@
|
|||
}
|
||||
},
|
||||
"node_modules/discord.js": {
|
||||
"version": "12.5.1",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz",
|
||||
"integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==",
|
||||
"version": "12.5.3",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz",
|
||||
"integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "^0.1.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prism-media": "^1.2.2",
|
||||
"prism-media": "^1.2.9",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
"ws": "^7.4.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
|
@ -1105,18 +1105,18 @@
|
|||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"discord.js": {
|
||||
"version": "12.5.1",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz",
|
||||
"integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==",
|
||||
"version": "12.5.3",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz",
|
||||
"integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==",
|
||||
"requires": {
|
||||
"@discordjs/collection": "^0.1.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prism-media": "^1.2.2",
|
||||
"prism-media": "^1.2.9",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
"ws": "^7.4.4"
|
||||
}
|
||||
},
|
||||
"enabled": {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"@supabase/supabase-js": "^1.7.7",
|
||||
"@thaldrin/sourcefinder": "^1.0.0",
|
||||
"chalk": "^4.1.0",
|
||||
"discord.js": "^12.5.1",
|
||||
"discord.js": "^12.5.3",
|
||||
"winston": "^3.3.3",
|
||||
"winston-daily-rotate-file": "^4.5.1",
|
||||
"yiff": "^3.0.3"
|
||||
|
|
|
@ -32,11 +32,14 @@ export = {
|
|||
// ? Get Server Config
|
||||
let { data: server_data, error: server_error } = await supabase.from<Server>("servers").select().eq(`server_id`, message.guild.id).limit(1)
|
||||
|
||||
// ? Check if Message includes shortlinks
|
||||
await Shortlink(message, server_data[0].shortlinks)
|
||||
|
||||
|
||||
// ! Prefix
|
||||
let PrefixArray: string[] = [...config.variables.prefix, [(server_data[0].prefix ? server_data[0].prefix : [])]].flat(Infinity)
|
||||
console.log(`Prefixes for ${message.guild.name} | `, PrefixArray)
|
||||
|
||||
Shortlink(message.content, server_data[0].shortlinks)
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import Logger from "../utils/logger";
|
|||
export = {
|
||||
name: "messageUpdate",
|
||||
run: async (client: Client, old_message: Message, new_message: Message) => {
|
||||
if (new_message.author.bot || old_message.author.bot) return
|
||||
Logger.info({ type: `event:messageUpdate`, message: "Emitting new message to event:message" })
|
||||
await client.emit("message", new_message)
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Initial code taken from @Cynosphere, rewritten by me
|
||||
const Regex = /(?:\s|^)(gh|gl|yt|tw|npm|tv|bc|bcu|wc|sc|bot|fav|fau)\/([a-zA-Z0-9-_.#@/!]*)/g;
|
||||
const Links: {
|
||||
[value: string]: string
|
||||
} = {
|
||||
|
||||
const Regex =
|
||||
/(?:\s|^)(gh|gl|yt|tw|npm|tv|bc|bcu|wc|sc|bot|fav|fau)\/([a-zA-Z0-9-_.#@/!]*)/g;
|
||||
|
||||
const Links: { [value: string]: string } = {
|
||||
"gh": "https://github.com/$link$",
|
||||
"gl": "https://gitlab.com/$link$",
|
||||
"yt": "https://youtu.be/$link$",
|
||||
|
@ -16,7 +17,7 @@ const Links: {
|
|||
// fa: "https://furaffinity.net/$link$",
|
||||
"fav": "https://furaffinity.net/view/$link$",
|
||||
"fau": "https://furaffinity.net/user/$link$",
|
||||
"bot": "https://discordapp.com/oauth2/authorize?client_id=$link$&scope=bot"
|
||||
"bot": "https://discordapp.com/oauth2/authorize?client_id=$link$&scope=bot",
|
||||
};
|
||||
const SiteNames = {
|
||||
gh: "Github",
|
||||
|
@ -33,25 +34,23 @@ const SiteNames = {
|
|||
bcu: "Bandcamp User",
|
||||
sc: "Soundcloud",
|
||||
bot: "Bot Invites",
|
||||
wc: "werewolf.codes"
|
||||
wc: "werewolf.codes",
|
||||
};
|
||||
|
||||
export default async function Shortlink(content: string) {
|
||||
let Possible: string[] = []
|
||||
let res = content.match(Regex)
|
||||
console.log(res)
|
||||
let Possible: string[] = [];
|
||||
let res = content.match(Regex);
|
||||
if (!res) return;
|
||||
res = res.map(x => (x.startsWith(' ') ? x.substring(1) : x))
|
||||
res = res.map((x) => (x.startsWith(" ") ? x.substring(1) : x));
|
||||
for (const Shortlink in res) {
|
||||
for (const Link in Links) {
|
||||
let content = res[Shortlink]
|
||||
let content = res[Shortlink];
|
||||
if (!content.startsWith(Link)) continue;
|
||||
content = content.replace(Link + '/', "")
|
||||
content = Links[Link].replace("$link$", content)
|
||||
Possible.push(content)
|
||||
content = content.replace(Link + "/", "");
|
||||
content = Links[Link].replace("$link$", content);
|
||||
Possible.push(`<${content}>`);
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
return Possible.join('\n')
|
||||
|
||||
}
|
||||
return Possible;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
import sourcefinder from "./sourcefinder";
|
||||
import shortlink from "./shortlink";
|
||||
import { Message } from "discord.js";
|
||||
import { Message, TextChannel } from "discord.js";
|
||||
|
||||
|
||||
let SL = /(nosl|no-?short(link(s|ing)?)?)/gmi
|
||||
let SF = /(nosf|no-?source(find(er|ing)?)?)/gmi
|
||||
|
||||
|
||||
async function check(content: string, feature: string) {
|
||||
function disabled(message: Message, feature: string) {
|
||||
|
||||
switch (feature) {
|
||||
case 'sl':
|
||||
console.log(content.match(SL))
|
||||
break;
|
||||
// @ts-ignore
|
||||
return SL.test((message.channel as TextChannel).topic)
|
||||
|
||||
default:
|
||||
break;
|
||||
throw new Error("No Feature was defined.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +23,11 @@ async function check(content: string, feature: string) {
|
|||
|
||||
export default async function Shortlink(message: Message, setting: boolean) {
|
||||
if (!setting) return;
|
||||
let enabled = await check(message.content, 'sl')
|
||||
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"))
|
||||
|
||||
}
|
Loading…
Reference in New Issue