aya-helper
Version:
This is a new package, that can help you with moderation, tickets, fun commands, nsfw and anime commands.
555 lines (554 loc) • 20.3 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimeRequest = exports.AyaAnime = exports.NsfwRequest = exports.AyaNsfw = exports.FunRequest = exports.MemeRequest = exports.AyaFun = exports.Ticket = exports.AyaTickets = exports.Balance = exports.Item = exports.Shop = exports.Inventory = exports.AyaEconomy = exports.Infraction = exports.AyaModeration = void 0;
const axios_1 = __importDefault(require("axios"));
const discord_js_1 = require("discord.js");
const quickmongo_1 = require("quickmongo");
const uuid_1 = require("uuid");
class AyaHelper {
constructor(client, mongoUrl, onConnecting, onConnect, onError) {
this.client = client;
this.mongoUrl = mongoUrl;
this.db = new quickmongo_1.Database(mongoUrl);
this.db.connect();
this.db.on('connecting', () => onConnecting());
this.db.on('connected', () => onConnect());
this.db.on('error', () => onError());
this.moderation = new AyaModeration(this.db, client);
this.economy = new AyaEconomy(this.db, client);
this.tickets = new AyaTickets(this.db, client);
this.fun = new AyaFun(client);
this.nsfw = new AyaNsfw(client);
this.anime = new AyaAnime(client);
}
}
exports.default = AyaHelper;
class AyaModeration {
constructor(db, client) {
this.db = db;
this.client = client;
}
async timeout(member, time, reason = 'No Reason') {
return member.timeout(time, reason)
.then(() => true)
.catch(() => false);
}
async ban(member, reason = 'No Reason', soft = false) {
return member.ban({
reason: reason
}).then(() => {
if (soft) {
return member.guild.bans.remove(member.user.id, reason)
.then(() => true)
.then(() => false);
}
return true;
}).catch(() => false);
}
async kick(member, reason = 'No Reason') {
return member.kick(reason)
.then(() => true)
.catch(() => false);
}
async purge(channel, amount) {
return channel.bulkDelete(amount)
.then(() => true)
.catch(() => false);
}
async infractions(member) {
var _a;
let inf = (_a = await this.db.get(`infractions_${member.user.id}`)) !== null && _a !== void 0 ? _a : [];
return inf.map(a => new Infraction(member, a.type, a.reason));
}
async addInfraction(infraction) {
var _a;
let inf = (_a = await this.db.get(`infractions_${infraction.member.user.id}`)) !== null && _a !== void 0 ? _a : [];
inf.push({
id: infraction.id,
member: infraction.member.user.id,
type: infraction.type,
reason: infraction.reason
});
await this.db.set(`infractions_${infraction.member.user.id}`, inf);
}
async removeInfraction(user, id) {
var _a;
let inf = (_a = await this.db.get(`infractions_${user.id}`)) !== null && _a !== void 0 ? _a : [];
let infraction = inf.find(a => a.id === id);
if (!infraction)
return null;
await this.db.set(`infractions_${user.id}`, inf.filter(a => a.id != id));
return infraction;
}
}
exports.AyaModeration = AyaModeration;
class Infraction {
constructor(member, type, reason) {
this.id = uuid_1.v5();
this.member = member;
this.type = type !== null && type !== void 0 ? type : 'UNKNOWN';
this.reason = reason || 'No Reason provided';
}
}
exports.Infraction = Infraction;
class AyaEconomy {
constructor(db, client) {
this.db = db;
this.client = client;
}
async balance(member) {
var _a;
let balance = (_a = await this.db.get(`balance_${member.user.id}`)) !== null && _a !== void 0 ? _a : this.getDefaultBalance();
return new Balance(balance.wallet, balance.bank, balance.totalBank);
}
async add(member, amount, type) {
var _a, _b, _c, _d;
let balance = (_a = await this.db.get(`balance_${member.user.id}`)) !== null && _a !== void 0 ? _a : this.getDefaultBalance();
if (type === 'WALLET')
balance.wallet = ((_b = balance.wallet) !== null && _b !== void 0 ? _b : 0) + amount;
if (type === 'BANK')
balance.bank = ((_c = balance.bank) !== null && _c !== void 0 ? _c : 0) + amount;
if (type === 'TOTAL_BANK')
balance.totalBank = ((_d = balance.totalBank) !== null && _d !== void 0 ? _d : 0) + amount;
await this.db.set(`balance_${member.user.id}`, balance);
return new Balance(balance.wallet, balance.bank, balance.totalBank);
}
async remove(member, amount, type) {
var _a, _b, _c, _d;
let balance = (_a = await this.db.get(`balance_${member.user.id}`)) !== null && _a !== void 0 ? _a : this.getDefaultBalance();
if (type === 'WALLET')
balance.wallet = ((_b = balance.wallet) !== null && _b !== void 0 ? _b : 0) - amount;
if (type === 'BANK')
balance.bank = ((_c = balance.bank) !== null && _c !== void 0 ? _c : 0) - amount;
if (type === 'TOTAL_BANK')
balance.totalBank = ((_d = balance.totalBank) !== null && _d !== void 0 ? _d : 0) - amount;
await this.db.set(`balance_${member.user.id}`, balance);
return new Balance(balance.wallet, balance.bank, balance.totalBank);
}
getDefaultBalance() {
return { wallet: 0, bank: 0, totalBank: 0 };
}
async shop() {
return new Shop([
new Item('coming soon', 200)
]);
}
async inventory(member) {
var _a;
let inventory = (_a = await this.db.get(`inventory_${member.user.id}`)) !== null && _a !== void 0 ? _a : {
member: null,
items: []
};
return new Inventory(member, inventory.items);
}
async addItem(member, item) {
var _a;
let inventory = (_a = await this.db.get(`inventory_${member.user.id}`)) !== null && _a !== void 0 ? _a : {
member: null,
items: [],
};
inventory.items.push(item);
await this.db.set(`inventory_${member.user.id}`, inventory);
return new Inventory(member, inventory.items);
}
async removeItem(member, name, amount) {
var _a;
let inventory = (_a = await this.db.get(`inventory_${member.user.id}`)) !== null && _a !== void 0 ? _a : {
member: null,
items: []
};
inventory.items = inventory.items.map(a => {
if (a.name === name) {
a.amount = a.amount - amount;
if (a.amount <= 0) {
return null;
}
}
return a;
}).filter(a => a != null);
await this.db.set(`inventory_${member.user.id}`, inventory);
return new Inventory(member, inventory.items);
}
}
exports.AyaEconomy = AyaEconomy;
class Inventory {
constructor(member, items) {
this.member = member;
this.items = items;
}
}
exports.Inventory = Inventory;
class Shop {
constructor(items) {
this.items = items;
}
}
exports.Shop = Shop;
class Item {
constructor(name, cost, amount, icon, owned) {
this.name = name;
this.cost = cost;
this.amount = amount;
this.icon = icon;
this.owned = owned;
}
}
exports.Item = Item;
class Balance {
constructor(wallet, bank, totalBank) {
this.wallet = wallet;
this.bank = bank;
this.totalBank = totalBank;
}
}
exports.Balance = Balance;
class AyaTickets {
constructor(db, client) {
this.db = db;
this.client = client;
}
async getAll(guildId) {
let all = (await this.db.all()).filter((a) => {
return guildId ? (a.ID.startsWith('ticket-') && a.data.guild === guildId) : a.ID.startsWith('ticket-');
});
return all.map((a) => {
let guild = this.client.guilds.cache.get(a.data.guild);
return new Ticket(guild, guild.members.cache.get(a.data.user).user, guild.channels.cache.get(a.data.channel));
});
}
async removeAll(guildId) {
let all = (await this.db.all()).filter((a) => a.ID.startsWith('ticket-') && a.data.guild === guildId);
try {
all.forEach((a) => {
this.db.delete(a.ID);
});
return true;
}
catch (err) {
return false;
}
}
async get(member) {
let t = await this.db.get(`ticket-${member.user.id}`);
let guild = this.client.guilds.cache.get(t.guild);
return new Ticket(guild, member.user, guild.channels.cache.get(t.channel));
}
async find(id) {
let t = await this.db.get(`ticket-${id}`);
let guild = this.client.guilds.cache.get(t.guild);
return new Ticket(guild, guild.members.cache.get(id).user, guild.channels.cache.get(t.channel));
}
async remove(id) {
let tickets = await this.getAll();
let ticket = tickets.find(a => a.id === id);
if (!ticket)
return null;
await this.db.delete(`ticket-${id}`);
return ticket;
}
async create(member) {
let g = member.guild;
return g.channels.create(`ticket-${member.user.id}`, {
permissionOverwrites: [{
type: 'role',
id: g.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
}, {
type: 'member',
id: member.user.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES']
}]
}).then((c) => {
let ticket = new Ticket(g, member.user, c);
this.db.set(`ticket-${member.user.id}`, {
guild: g.id,
user: member.user.id,
channel: c.id
}, -1);
return ticket;
}).catch(() => null);
}
}
exports.AyaTickets = AyaTickets;
class Ticket {
constructor(guild, user, channel) {
this.guild = guild;
this.user = user;
this.channel = channel;
this.id = user.id;
}
}
exports.Ticket = Ticket;
class AyaFun {
constructor(client) {
this.client = client;
}
eightBall(answers) {
return answers[Math.floor(Math.random() * answers.length)];
}
async rps(user, user2, interaction) {
let rps = ['Rock', 'Paper', 'Scissors'];
let icons = ['🗻', '📰', '✂'];
await interaction.deferReply();
let msg = await interaction.editReply({
embeds: [{
title: 'Rock Paper Scissors',
description: `${user.user} vs. ${user2.user}\n??? - ???\nWinner: ???`,
color: 'BLURPLE',
timestamp: new Date()
}]
});
let answered = [false, false];
let chosen = ['???', '???'];
[user, user2].forEach(async (u, i) => {
let other = null;
if (i === 1)
other = user;
other = user2;
let d = await u.user.send({
embeds: [{
title: 'Choose',
description: `Choose between ${icons[0]} (Rock), ${icons[1]} (Paper), ${icons[2]} (Scissors)`,
color: 'GREEN',
timestamp: new Date(),
footer: {
text: `You are against ${other.user.tag}`,
iconURL: other.user.displayAvatarURL({
dynamic: true,
format: 'png'
})
}
}],
components: [new discord_js_1.MessageActionRow().addComponents([
new discord_js_1.MessageButton()
.setEmoji(icons[0])
.setLabel(rps[0])
.setStyle('PRIMARY')
.setCustomId(rps[0])
])]
});
d.awaitMessageComponent({
filter: (m) => rps.includes(m.customId),
componentType: 'BUTTON'
}).then(async (bt) => {
bt.reply(`Thanks for choosing! Wait for your opponent to choose! <#${interaction.channelId}>`);
let random = Math.floor(Math.random() * rps.length);
answered[i] = true;
chosen[i] = `${icons[random]} ${rps[random]}`;
if (answered[0] === true && answered[1] === true) {
let winner = '???';
let c1 = chosen[0];
let c2 = chosen[1];
if ((c1.includes('Rock') && c2.includes('Paper')) ||
(c1.includes('Scissors') && c2.includes('Paper')) ||
(c1.includes('Rock') && c2.includes('Scissors'))) {
winner = c1;
}
else if ((c2.includes('Rock') && c1.includes('Paper')) ||
(c2.includes('Scissors') && c1.includes('Paper')) ||
(c2.includes('Rock') && c1.includes('Scissors'))) {
winner = c2;
}
else {
winner = 'No one';
}
await interaction.editReply({
embeds: [{
title: 'Rock Paper Scissors',
description: `${user.user} vs. ${user2.user}\n${chosen[0]} - ${chosen[1]}\nWinner: ${winner === '???' ? 'Couldn\'t find a winner' : (winner === 'No one' ? 'It\'s a tie!' : winner)}`,
color: 'BLURPLE',
timestamp: new Date()
}]
});
}
});
});
}
coinflip() {
let sides = ['tails', 'heads'];
return sides[Math.floor(Math.random() * sides.length)];
}
async bird() {
return (0, axios_1.default)('http://shibe.online/api/birds')
.then((r) => new FunRequest(r.data[0]));
}
async birdfact() {
return (0, axios_1.default)('https://some-random-api.ml/animal/fox')
.then((r) => r.data.fact);
}
async cat() {
return (0, axios_1.default)('http://shibe.online/api/cats')
.then(r => new FunRequest(r.data[0]));
}
async dog() {
return (0, axios_1.default)('http://shibe.online/api/shibes')
.then(r => new FunRequest(r.data[0]));
}
async fox() {
return (0, axios_1.default)('https://randomfox.ca/floof')
.then(r => new FunRequest(r.data.image));
}
async foxfact() {
return (0, axios_1.default)('https://some-random-api.ml/animal/fox')
.then(r => r.data.fact);
}
async panda() {
return (0, axios_1.default)('https://some-random-api.ml/animal/panda')
.then(r => new FunRequest(r.data.image));
}
async pandafact() {
return (0, axios_1.default)('https://some-random-api.ml/animal/panda')
.then(r => r.data.fact);
}
async catfact() {
return (0, axios_1.default)('https://some-random-api.ml/animal/cat')
.then(r => r.data.fact);
}
async dogfact() {
return (0, axios_1.default)('https://some-random-api.ml/animal/dog')
.then(r => r.data.fact);
}
async meme() {
return (0, axios_1.default)('https://some-random-api.ml/meme')
.then(r => new MemeRequest(r.data.caption, r.data.image));
}
gayify(member) {
let link = 'https://some-random-api.ml/canvas/gay?avatar=' + member.user.displayAvatarURL({
dynamic: false,
format: 'png'
});
return new FunRequest(link);
}
jail(member) {
let link = 'https://some-random-api.ml/canvas/jail?avatar=' + member.user.displayAvatarURL({
dynamic: false,
format: 'png'
});
return new FunRequest(link);
}
triggered(member) {
let link = 'https://some-random-api.ml/canvas/triggered?avatar=' + member.user.displayAvatarURL({
dynamic: false,
format: 'png'
});
return new FunRequest(link);
}
}
exports.AyaFun = AyaFun;
class MemeRequest {
constructor(title, image) {
this.title = title;
this.image = image;
}
}
exports.MemeRequest = MemeRequest;
class FunRequest {
constructor(image) { this.image = image; }
}
exports.FunRequest = FunRequest;
class AyaNsfw {
constructor(client) {
this.client = client;
}
async hentai() {
return await this.request('Random_hentai_gif');
}
async neko() {
return await this.request('nsfw_neko_gif');
}
async lesbian() {
return await this.request('les');
}
async kuni() {
return await this.request('les');
}
async cumsluts() {
return await this.request('cum');
}
async classic() {
return await this.request('classic');
}
async boobs() {
return await this.request('boobs');
}
async blowjob() {
return await this.request('bj');
}
async yuri() {
return await this.request('yuri');
}
async tits() {
return await this.request('tits');
}
async solo() {
return await this.request('solog');
}
async feet() {
return await this.request('feetg');
}
async request(type) {
return await (0, axios_1.default)({
url: `https://nekos.life/api/v2/img/` + type,
}).then(r => {
return new NsfwRequest(type, r.data.url);
}).catch(e => {
console.log(e.isAxiosError ? e.toJSON() : e);
return new NsfwRequest(type, null);
});
}
}
exports.AyaNsfw = AyaNsfw;
class NsfwRequest {
constructor(type, image) {
this.type = type;
this.image = image;
}
}
exports.NsfwRequest = NsfwRequest;
class AyaAnime {
constructor(client) {
this.client = client;
}
async slap(user, user2) {
return await this.request('slap');
}
async poke(user, user2) {
return await this.request('poke');
}
async pat(user, user2) {
return await this.request('pat');
}
async tickle(user, user2) {
return await this.request('tickle');
}
async cuddle(user, user2) {
return await this.request('cuddle');
}
async kiss(user, user2) {
return await this.request('kiss');
}
async meow(user, user2) {
return await this.request('meow');
}
async waifu() {
return await this.request('waifu');
}
async request(type) {
return await (0, axios_1.default)({
url: `https://nekos.life/api/v2/img/` + type,
}).then(r => {
return new AnimeRequest(type, r.data.url);
}).catch(e => {
console.log(e.isAxiosError ? e.toJSON() : e);
return new AnimeRequest(type, null);
});
}
}
exports.AyaAnime = AyaAnime;
class AnimeRequest {
constructor(type, image) { this.type = type; this.image = image; }
}
exports.AnimeRequest = AnimeRequest;