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