v4 startin now

This commit is contained in:
ry 2020-02-16 20:30:02 +01:00
parent ce774e0f09
commit 26236cf8a5
57 changed files with 161 additions and 8045 deletions

28
utils/index.js Executable file → Normal file
View file

@ -1,21 +1,9 @@
const {
Permissions: {
FLAGS
}
} = require('discord.js');
module.exports = {
topic: require('./src/TopicSettings'),
format: require('./src/format'),
status: require('./src/statuses'),
calc: require('./src/calc'),
ShortLinks: require('./src/shortlinks'),
SourceFynnder: require('./src/sourceFynnder'),
emotes: require('./src/emotes'),
db: require('./src/database'),
log: require('./src/logs'),
int: require('./src/interactions'),
eco: require('./src/economy'),
discord: require('discord.js'),
yiff: require('yiff'),
perms: FLAGS
};
db: require('./src/database'),
eco: require('./src/economy'),
emotes: require('./src/emotes'),
ints: require('./src/interactions'),
Shortlinks: require('./src/Shortlinks'),
SourceFynnder: require('./src/SourceFynnder'),
TopicSettings: require('./src/TopicSettings')
}

View file

@ -1,20 +0,0 @@
module.exports = {
userDays: function (user) {
if (typeof user !== "object") throw new TypeError("Not an Object");
let creation = new Date().getTime() - user.createdAt.getTime();
let days = creation / 1000 / 60 / 60 / 24;
return Math.round(days);
},
serverDays: function (server) {
if (typeof server !== "object") throw new TypeError("Not an Object");
let creation = new Date().getTime() - server.createdAt.getTime();
let days = creation / 1000 / 60 / 60 / 24;
return Math.round(days);
}
};

195
utils/src/database.js Executable file → Normal file
View file

@ -1,187 +1,12 @@
const db = require("quick.db");
const Servers = new db.table("servers");
const Users = new db.table("users");
//const { prefixes } = require('../../config');
const chalk = require("chalk");
const sch = {
server: require('../../models/Server'),
user: require('../../models/User')
}
const DatabaseDefaults = {
user: {
id: null,
blacklist: {
state: false,
replied: false,
reason: undefined
}
},
server: {
prefix: [],
SourceFynnder: false,
Shortlinks: false,
embeds: true,
rp_text: true,
default_yiff: "gay"
}
};
module.exports = {
defaults: DatabaseDefaults,
setupServer: async function (ctx) {
ctx.utils.log.servers.setup(ctx.guild);
if (Servers.get(ctx.guild.id) === null) {
await Servers.set(ctx.guild.id, DatabaseDefaults.server);
}
ctx.utils.log.servers.fin(ctx.guild);
return true;
},
prefix: {
add: async function (ctx, Prefix) {
let Prefixes = [];
let New;
Prefixes = await Servers.get(ctx.guild.id).prefix;
if (Prefixes.includes(Prefix))
throw new Error("Prefix already in Database");
else {
New = await Servers.push(`${ctx.guild.id}.prefix`, Prefix);
}
return New;
},
remove: async function (ctx, Prefix) {
if (DatabaseDefaults.server.prefix.includes(Prefix)) {
throw new Error("You cannot remove the Default Prefix(es)");
}
let Prefixes = ctx.db.servers.get(ctx.guild.id).prefix;
if (!Prefixes.includes(Prefix)) {
throw new Error("Prefix does not exist in Database");
}
let index = Prefixes.indexOf(Prefix);
Prefixes.splice(index, 1);
await Servers.set(`${ctx.guild.id}.prefix`, Prefixes);
}
},
toggle: {
SourceFynnder: async function (ctx) {
let Server = await Servers.get(ctx.guild.id);
Server.SourceFynnder ?
console.log(
`${chalk.green("✔")} Set ${chalk.blue(
"SourceFynnder"
)} in ${chalk.magenta(ctx.guild.id)} to ${chalk.red("false")} `
) :
console.log(
`${chalk.green("✔")} Set ${chalk.blue(
"SourceFynnder"
)} in ${chalk.magenta(ctx.guild.id)} to ${chalk.green("true")} `
);
Server.SourceFynnder ?
await Servers.set(`${ctx.guild.id}.SourceFynnder`, false) :
await Servers.set(`${ctx.guild.id}.SourceFynnder`, true);
},
Shortlinks: async function (ctx) {
let Server = await Servers.get(ctx.guild.id);
Server.Shortlinks ?
console.log(
`${chalk.green("✔")} Set ${chalk.blue(
"Shortlinks"
)} in ${chalk.magenta(ctx.guild.id)} to ${chalk.red("false")} `
) :
console.log(
`${chalk.green("✔")} Set ${chalk.blue(
"Shortlinks"
)} in ${chalk.magenta(ctx.guild.id)} to ${chalk.green("true")} `
);
Server.Shortlinks ?
await Servers.set(`${ctx.guild.id}.Shortlinks`, false) :
await Servers.set(`${ctx.guild.id}.Shortlinks`, true);
},
Embeds: async function (ctx) {
let Server = await Servers.get(ctx.guild.id);
Server.embeds ?
console.log(
`${chalk.green("✔")} Set ${chalk.blue("Emdeds")} in ${chalk.magenta(
ctx.guild.id
)} to ${chalk.red("false")} `
) :
console.log(
`${chalk.green("✔")} Set ${chalk.blue("Embeds")} in ${chalk.magenta(
ctx.guild.id
)} to ${chalk.green("true")} `
);
Server.embeds ?
await Servers.set(`${ctx.guild.id}.embeds`, false) :
await Servers.set(`${ctx.guild.id}.embeds`, true);
},
Text: async function (ctx) {
let Server = await Servers.get(ctx.guild.id);
Server.rp_text ?
console.log(
`${chalk.green("✔")} Set ${chalk.blue(
"RP Text"
)} in ${chalk.magenta(ctx.guild.id)} to ${chalk.red("false")} `
) :
console.log(
`${chalk.green("✔")} Set ${chalk.blue(
"RP Text"
)} in ${chalk.magenta(ctx.guild.id)} to ${chalk.green("true")} `
);
Server.rp_text ?
await Servers.set(`${ctx.guild.id}.rp_text`, false) :
await Servers.set(`${ctx.guild.id}.rp_text`, true);
}
},
blacklist: async function (user, kind, reason) {
switch (kind) {
case "add":
case "a":
let Y = await Users.set(user, {
id: user,
blacklist: {
state: true,
replied: false,
reason: reason
}
});
return Y;
break;
case "remove":
case "r":
let Z = await Users.set(user, {
id: user,
blacklist: {
state: false,
replied: false,
reason: undefined
}
});
return Z;
break;
case "check":
case "status":
case "c":
case "s":
//let X = await Users.get(user);
//console.log(X)
//if (X === null) X = DatabaseDefaults.user
//if(X.blacklist === null)
let W = await Users.get(user)
let X = DatabaseDefaults.user.blacklist
if (W === null) K = X
else if (W.blacklist === undefined || W.blacklist === null) K = X
else K = W.blacklist
//console.log(K)
return K
break;
default:
break;
}
}
};
async function blacklist(user, state, reason) {
console.log(`called .blacklist() with
User: ${user}
State: ${state}
Reason: ${reason}`)
}

View file

@ -1,22 +0,0 @@
module.exports = {
bold: function (str) {
return `**${str}**`;
},
italic: function (str) {
return `*${str}*`;
},
code: function (str) {
return `\`${str}\``;
},
uptime: function (seconds) {
function pad(s) {
return (s < 10 ? '0' : '') + s;
}
var hours = Math.floor(seconds / (60 * 60));
var minutes = Math.floor((seconds % (60 * 60)) / 60);
var seconds = Math.floor(seconds % 60);
return pad(hours) + 'h ' + pad(minutes) + 'm ' + pad(seconds) + 's';
}
};

View file

@ -1,49 +0,0 @@
const ora = require("ora");
const vars = require("../../vars");
const chalk = require("chalk");
const BotSpinner = new ora({
discardStdin: false
});
const shardSpinner = new ora({
discardStdin: false
});
const ServerSpinner = new ora({
discardStdin: false
});
module.exports = async = {
starting: async function () {
BotSpinner.text = `${vars.name} - v${vars.version} is starting`;
BotSpinner.spinner = "moon";
BotSpinner.start();
return BotSpinner;
},
stopSpinner: function () {
return BotSpinner.stop();
},
hasStarted: async function () {
BotSpinner.succeed(`${vars.name} - v${vars.version} has started`);
return;
},
shardReady: async function (text) {
shardSpinner.text = text;
shardSpinner.spinner = "moon";
return shardSpinner.start();
},
shardSpinnerStarted: function () {
return shardSpinner.succeed();
},
servers: {
setup: async function (server) {
ServerSpinner.text = `Setting up ${chalk.red(server.name)} | ${chalk.red(
server.id
)}...`;
ServerSpinner.start();
},
fin: async function (server) {
ServerSpinner.succeed(
`${chalk.red(server.name)} | ${chalk.red(server.id)} has been set up.`
);
}
}
};

View file

@ -1,80 +0,0 @@
const ShortLinkReg = /(?:\s|^)(gh|gl|gd|owo|aud|sg|ttv|teknik|bb|yt|bc|bcu|sc|bot|sw|tw|npm|xkcd)\/([a-zA-Z0-9-_.#/!]*)/g;
const ShortLinks = {
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$',
ttv: 'https://twitch.tv/$link$',
gd: 'https://gitdab.com/$link$',
owo: 'https://owo.codes/$link$',
sg: 'https://git.supernets.org/$link$',
teknik: 'https://git.teknik.io/$link$',
bb: 'https://bitbucket.org/$link$',
bc: 'https://$link$.bandcamp.com/',
bcu: 'https://bandcamp.com/$link$',
sc: 'https://soundcloud.com/$link$',
aud: 'https://audius.co/$link$',
// aur: 'https://aur.archlinux.org/packages/$link$',
sw: 'https://steamcommunity.com/sharedfiles/filedetails/?id=$link$',
bot: '<https://discordapp.com/oauth2/authorize?client_id=$link$&scope=bot>',
xkcd: 'https://xkcd.com/$link$'
};
const ShortLinkDirs = {
gh: 'Github',
gl: 'Gitlab',
gd: 'Gitdab',
yt: 'Youtube',
tw: 'Twitter',
npm: 'NPM',
ttv: 'TwitchTv',
owo: 'owo_codes',
sg: 'Supernets_Git',
aud: 'Audius',
teknik: 'Teknik_Git',
bb: 'BitBucket',
bc: 'Bandcamp_Band',
bcu: 'Bandcamp_User',
sc: 'Soundcloud',
// aur: 'Arch_Packages',
sw: 'Steam_Workshop',
bot: 'Discord_Bot_Invite',
xkcd: 'xkcd'
};
const db = require('quick.db');
const backend = new db.table('backend');
module.exports = async function Shortlink(enabled, msg) {
if (!enabled || enabled === null || enabled === undefined) return;
let res = msg.content.match(ShortLinkReg);
if (!res) return;
res = res.map((x) => (x.startsWith(' ') ? x.substring(1) : x));
let links = [];
let Amount = [];
for (const m in res) {
for (const x in ShortLinks) {
let url = res[m];
if (!url.startsWith(x)) continue;
url = url.replace(x + '/', '');
if (x == 'gh' || x == 'gl' || x == 'gd') {
url = url.replace('#', '/issues/');
}
if (x == 'gl') {
url = url.replace('!', '/merge_requests/');
} else if (x == 'gd') {
url = url.replace('!', '/pulls/');
} else if (x == 'gh') {
url = url.replace('!', '/pull/');
}
url = ShortLinks[x].replace('$link$', url);
links.push(`${url}`);
await backend.add(`Shortlink.${ShortLinkDirs[x]}`, 1);
await backend.add(`Shortlink.total`, 1);
}
}
msg.channel.send(links.join('\n'));
};

View file

@ -1,78 +0,0 @@
const axios = require('axios');
const db = require('quick.db');
const backend = new db.table('backend');
const Servers = new db.table('servers');
let 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'
);
let search_md5 = 'https://e621.net/post/show.json?md5=';
let e6 = 'https://e621.net/post/show/';
let e9 = 'https://e926.net/post/show/';
const version = '0.1.0';
async function SourceFynnderBot(enabled, msg) {
if (!enabled || enabled === null || enabled === undefined) return;
res = msg.content.match(md5);
if (!res) return;
let Sources = [];
for (const m in res) {
let URL = res[m];
let hash = URL.split(md5)[2];
let {
data
} = await axios.get(search_md5 + hash, {
headers: {
'user-agent': `SourceFynnder/${version} (ry / codepupper)`
}
});
if (data.rating === 's') {
Source = e9 + data.id;
} else {
Source = e6 + data.id;
}
Sources.push(`:link::mag: ${Source}`);
}
msg.channel.send(Sources);
await backend.add('SourceFynnder.found', Sources.length);
await backend.add('SourceFynnder.foundBot', Sources.length);
await Servers.add(`${msg.guild.id}.foundSources`, Sources.length);
};
async function SourceFynnderAPI(url) {
url = url.toString().replace(/\,/g, ' ')
res = url.match(md5);
if (!res) throw new Error('Not a Valid e621/e926 URL');
let Sources = [];
for (const m in res) {
let URL = res[m];
let hash = URL.split(md5)[2];
let {
data
} = await axios.get(search_md5 + hash, {
headers: {
'user-agent': `SourceFynnder/${version} (ry / codepupper)`
}
});
if (data.rating === 's') {
Source = e9 + data.id;
} else {
Source = e6 + data.id;
}
Sources.push(`${Source}`);
}
await backend.add('SourceFynnder.found', Sources.length);
await backend.add('SourceFynnder.foundAPI', Sources.length);
return Sources
};
module.exports = {
SourceFynnder: SourceFynnderBot,
APIFind: SourceFynnderAPI
}

View file

@ -1,121 +0,0 @@
function randomStatus(client) {
const States = [{
activity: {
name: 'server fans whirr 💨',
type: 'LISTENING'
},
status: 'online'
},
{
activity: {
name: 'True Damage - GIANTS',
type: 'LISTENING'
},
status: 'online'
},
{
activity: {
name: `${client.guilds.size} Servers -w-`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: 'Δ & ♫',
type: 'LISTENING'
},
status: 'online'
},
{
activity: {
name: `'help | thaldr.in`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `Linux Servers`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `e621 Videos`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `WannaCry`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `the Blockchain!`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `something... ;3`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `Skynet`,
type: 'WATCHING'
},
status: 'online'
},
{
activity: {
name: `Half Life`,
type: 'PLAYING'
},
status: 'online'
},
{
activity: {
name: `Half Life 2`,
type: 'PLAYING'
},
status: 'online'
},
{
activity: {
name: `Portal`,
type: 'PLAYING'
},
status: 'online'
},
{
activity: {
name: `Portal 2`,
type: 'PLAYING'
},
status: 'online'
}
// { game: { name: `over ${thal.users.get('318044130796109825').username}~`, type: 'WATCHING' }, status: 'dnd' }
];
let status = States[~~(Math.random() * States.length)];
return client.user.setPresence(status);
}
module.exports = {
playing: "PLAYING",
watching: "WATCHING",
listening: "LISTENING",
streaming: "STREAMING",
randomStatus
};