mirror of https://github.com/thaldrin/thaldrin.git
initial commit
This commit is contained in:
parent
58c72b4aab
commit
77e22c837f
|
@ -0,0 +1,2 @@
|
|||
config.ts
|
||||
node_modules/
|
12
README.md
12
README.md
|
@ -1 +1,11 @@
|
|||
# thaldrin
|
||||
# Thaldrin
|
||||
|
||||
Repo for Thaldrin V4, completely rewritten in [auguwu/wumpcord](https://github.com/auguwu/wumpcord)
|
||||
|
||||
# Licence
|
||||
|
||||
None yet, but Credit me if you use parts of my code.
|
||||
|
||||
|
||||
# Authors
|
||||
- Lio Melio - *Owner/Developer* - [@HimboLion](https://twitter.com/HimboLion)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@sniff/armpits": "^0.0.6",
|
||||
"axios": "^0.21.1",
|
||||
"leeks.js": "^0.0.9",
|
||||
"util": "^0.12.3",
|
||||
"wumpcord": "^1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.20"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
import { Client, MessageCreateEvent } from "wumpcord";
|
||||
import config from "./config"
|
||||
import { Shortlink } from "./utils/Message/shortlinks";
|
||||
import { SourceFinder } from "./utils/Message/sourcefinder";
|
||||
import Armpit from "@sniff/armpits";
|
||||
|
||||
const Armpits = new Armpit()
|
||||
|
||||
Armpits.info("Starting up...")
|
||||
|
||||
const client = new Client({
|
||||
token: config.TOKEN,
|
||||
interactions: true,
|
||||
ws: { intents: ['guilds', 'guildMessages'] }
|
||||
});
|
||||
|
||||
// Ignore the @ts-ignore lines, those are because of
|
||||
// inconsistent Typings within Wumpcord at the time of writing these files
|
||||
|
||||
client.on('message', async (event: MessageCreateEvent) => {
|
||||
if (event.message.author.bot) return;
|
||||
// Grab Server Settings from Redis Cache before doing anything?
|
||||
Shortlink(event, false)
|
||||
SourceFinder(event, true)
|
||||
// @ts-ignore
|
||||
if (event.message.content === '!ping') return await event.message.channel.reply("pong")
|
||||
});
|
||||
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`Connected as ${client.user.tag}!`);
|
||||
client.setStatus('online', { // Sets it to "Competing in uwu"
|
||||
type: 5,
|
||||
name: 'uwu'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
client.connect();
|
|
@ -0,0 +1,56 @@
|
|||
// 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 = {
|
||||
gh: "https://github.com/$link$",
|
||||
gl: "https://gitlab.com/$link$",
|
||||
yt: "https://youtu.be/$link$",
|
||||
tw: "https://twitter.com/$link$",
|
||||
npm: "https://npm.im/$link$",
|
||||
tv: "https://twitch.tv/$link$",
|
||||
bc: "https://$link$.bandcamp.com/",
|
||||
bcu: "https://bandcamp.com/$link$",
|
||||
wc: "https://werewolf.codes/$link$",
|
||||
sc: "https://soundcloud.com/$link$",
|
||||
// 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"
|
||||
};
|
||||
export const SiteNames = {
|
||||
gh: "Github",
|
||||
gl: "Gitlab",
|
||||
gd: "Gitdab",
|
||||
yt: "Youtube",
|
||||
tw: "Twitter",
|
||||
npm: "NPM",
|
||||
tv: "Twitch",
|
||||
// fa: "FurAffinity",
|
||||
fav: "FurAffinity Post",
|
||||
fau: "FurAffinity User",
|
||||
bc: "Bandcamp Band",
|
||||
bcu: "Bandcamp User",
|
||||
sc: "Soundcloud",
|
||||
bot: "Bot Invites",
|
||||
wc: "werewolf.codes"
|
||||
};
|
||||
import { MessageCreateEvent } from "wumpcord";
|
||||
export async function Shortlink(event: MessageCreateEvent, settings: boolean) {
|
||||
let Possible: string[] = []
|
||||
if (!settings || settings === null || settings === undefined) return;
|
||||
let res = event.message.content.match(Regex)
|
||||
console.log(res)
|
||||
if (!res) return;
|
||||
res = res.map(x => (x.startsWith(' ') ? x.substring(1) : x))
|
||||
for (const Shortlink in res) {
|
||||
for (const Link in Links) {
|
||||
let content = res[Shortlink]
|
||||
if (!content.startsWith(Link)) continue;
|
||||
content = content.replace(Link + '/', "")
|
||||
content = Links[Link].replace("$link$", content)
|
||||
Possible.push(content)
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
return event.message.channel.send(Possible.join('\n'))
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
import axios from "axios";
|
||||
import { MessageCreateEvent } from "wumpcord";
|
||||
const md5 = new RegExp(
|
||||
"((?:!)?https?://static[0-9]*.(?:e621|e926).net/data/(?:sample/|preview/|)[0-9a-f]{2}/[0-9a-f]{2}/([0-9a-f]{32}).([0-9a-z]+))",
|
||||
"igm"
|
||||
);
|
||||
const search_md5 = "https://e621.net/posts.json?md5=";
|
||||
const e6 = "https://e621.net/posts/";
|
||||
const e9 = "https://e926.net/posts/";
|
||||
const version = "0.3.0";
|
||||
|
||||
export async function SourceFinder(event: MessageCreateEvent, settings = true) {
|
||||
if (!settings || settings === null || settings === undefined) return;
|
||||
let Links = event.message.content.match(md5);
|
||||
if (!Links) return;
|
||||
|
||||
let Sources: string[] = []
|
||||
for (const index in Links) {
|
||||
let ImageURL = Links[index]
|
||||
let ImageHash = ImageURL.split(md5)[2]
|
||||
let { data } = await axios.get(`${search_md5}${ImageHash}`, {
|
||||
headers: {
|
||||
"User-Agent": `SourceFinder/${version} by hokkqi (https://kji.tf/twitter)`
|
||||
}
|
||||
})
|
||||
let source;
|
||||
switch (data.rating) {
|
||||
case 's':
|
||||
source = `${e9}${data.post.id}`
|
||||
break;
|
||||
default:
|
||||
source = `${e6}${data.post.id}`
|
||||
break;
|
||||
}
|
||||
Sources.push(`<${source}>`)
|
||||
}
|
||||
return event.message.reply(`:link: :mag:\n${Sources.join('\n')}`)
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* Copyright (c) 2020-2021 August
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { inspect } from 'util';
|
||||
import leeks from 'leeks.js';
|
||||
|
||||
// List of colors for the log levels
|
||||
const Colors = {
|
||||
debug: leeks.hex('#4F7CA3', '[Debug]'),
|
||||
error: leeks.hex('#FF2255', '[Error]'),
|
||||
warn: leeks.hex('#FFFFC5', '[Warn]'),
|
||||
info: leeks.hex('#BCD9FF', '[Info]')
|
||||
} as const;
|
||||
|
||||
type LogMessage = string | object | Error | any[] | Date | null | undefined | number | boolean;
|
||||
|
||||
enum LogLevel {
|
||||
Info = 'info',
|
||||
Warn = 'warn',
|
||||
Error = 'error',
|
||||
Debug = 'debug'
|
||||
}
|
||||
|
||||
export default class Logger {
|
||||
/** The logger's name */
|
||||
private name: string;
|
||||
|
||||
/**
|
||||
* Creates a new [Logger] instance
|
||||
* @param name The name of the [Logger]
|
||||
*/
|
||||
constructor(name: string) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private _getDate() {
|
||||
const current = new Date();
|
||||
|
||||
const hours = current.getHours();
|
||||
const minutes = current.getMinutes();
|
||||
const seconds = current.getSeconds();
|
||||
const month = current.getMonth() + 1;
|
||||
const day = current.getDate();
|
||||
const year = current.getFullYear();
|
||||
|
||||
return leeks.colors.gray(`[${day}/${month}/${year} @ ${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}]`);
|
||||
}
|
||||
|
||||
private _formatMessage(...messages: LogMessage[]): string {
|
||||
return messages.map<string>((message: unknown) => {
|
||||
if ([null, undefined].includes(<any>message)) return leeks.colors.cyan(message === null ? 'null' : 'undefined');
|
||||
if (message instanceof Array) return message.join('\n');
|
||||
if (message instanceof Date) return leeks.colors.cyan(message.toUTCString());
|
||||
if (message instanceof Error) {
|
||||
const e = [`${message.name}: ${message.message}`];
|
||||
const stack = message.stack ? message.stack.split('\n').map(s => s.trim()) : [];
|
||||
stack.shift();
|
||||
|
||||
const all = stack.map(s => {
|
||||
if (/(.+(?=)|.+) ((.+):\d+|[:\d+])[)]/g.test(s)) return s.match(/(.+(?=)|.+) ((.+):\d+|[:\d+])[)]/g)![0];
|
||||
if (/(.+):\d+|[:\d+][)]/g.test(s)) return s.match(/(.+):\d+|[:\d+][)]/g)![0];
|
||||
|
||||
return s;
|
||||
});
|
||||
|
||||
e.push(...all.map(item => ` • "${item.replace('at', '').trim()}"`));
|
||||
return e.join('\n');
|
||||
}
|
||||
|
||||
if (!['object', 'function', 'undefined', 'string'].includes(typeof message)) return leeks.colors.cyan(<any>message);
|
||||
if (typeof message === 'object') return inspect(message, { depth: null });
|
||||
|
||||
return message as any;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
private write(level: LogLevel, ...messages: LogMessage[]) {
|
||||
const lvlText = Colors[level];
|
||||
if (lvlText === undefined) throw new TypeError(`Invalid log level '${level}'`);
|
||||
|
||||
const message = this._formatMessage(...messages);
|
||||
const name = leeks.hex('#F4A4D2', `[${this.name}]`);
|
||||
const date = this._getDate();
|
||||
const stream = level === LogLevel.Error ? process.stderr : process.stdout;
|
||||
|
||||
stream.write(`${date} ${name} ${lvlText} ${message}\n`);
|
||||
}
|
||||
|
||||
info(...messages: LogMessage[]) {
|
||||
return this.write(LogLevel.Info, ...messages);
|
||||
}
|
||||
|
||||
warn(...messages: LogMessage[]) {
|
||||
return this.write(LogLevel.Warn, ...messages);
|
||||
}
|
||||
|
||||
error(...messages: LogMessage[]) {
|
||||
return this.write(LogLevel.Error, ...messages);
|
||||
}
|
||||
|
||||
debug(...messages: LogMessage[]) {
|
||||
return this.write(LogLevel.Debug, ...messages);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2019",
|
||||
"module": "CommonJS",
|
||||
"lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "ESNext"],
|
||||
"declaration": false,
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"moduleResolution": "node",
|
||||
"types": ["node"],
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
Loading…
Reference in New Issue