Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
iwa authored Aug 26, 2020
2 parents 4edc7c3 + 8cc734b commit 2ead8d9
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 303 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
- Language used : `TypeScript, with NodeJS`
- Library used : `discord.js`

[![BCH Compliance](https://bettercodehub.com/edge/badge/iwa/Kwako?branch=master)](https://bettercodehub.com/)
[![CodeFactor Grade](https://www.codefactor.io/repository/github/iwa/kwako/badge)](https://www.codefactor.io/repository/github/iwa/kwako)
[![DeepScan Grade](https://deepscan.io/api/teams/10640/projects/13488/branches/228346/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=10640&pid=13488&bid=228346)

## 🤝 Contributing

- Create a fork and clone it
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kwako",
"version": "1.0.5",
"version": "1.0.6",
"description": "",
"main": "build/index.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
"@types/pino": "^6.3.0",
"@types/ws": "^7.2.4",
"anilist-node": "^1.4.0",
"axios": "^0.19.2",
"bufferutil": "^4.0.1",
"canvas": "^2.6.1",
"discord.js": "^12.3.1",
Expand All @@ -33,7 +34,6 @@
"pino": "^6.5.1",
"popyt": "^4.1.1",
"sodium": "^3.0.2",
"timespan-parser": "^1.0.2",
"utf-8-validate": "^5.0.2",
"ytdl-core": "^3.2.1"
},
Expand Down
52 changes: 52 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import log from './Logger';

import { MongoClient, Db } from 'mongodb';

import axios from 'axios';

// MongoDB constants
const url = process.env.MONGO_URL, dbName = process.env.MONGO_DBNAME;

Expand All @@ -17,6 +19,9 @@ export default new class Kwako extends Client {

public commands: Collection<any, any> = new Collection();

public patrons: Set<string> = new Set();
private golden: Set<string> = new Set();

public constructor() {
super(
{
Expand All @@ -25,6 +30,46 @@ export default new class Kwako extends Client {
);
}

private async getPledgeData() {
const link = `https://www.patreon.com/api/oauth2/api/campaigns/3028203/pledges`;
return await axios
.get(link, {
headers: { authorization: `Bearer ${process.env.PATREON_TOKEN}` }
})
.then(async res => {
let golden: Set<string> = new Set();
let goldenId: Set<string> = new Set();
for(const thing of res.data.data)
if(thing.attributes.amount_cents >= 1000)
goldenId.add(thing.relationships.patron.data.id)

let users: Set<string> = new Set();
for(const thing of res.data.included)
if(thing.type === 'user')
if(thing.attributes.social_connections.discord) {
users.add(thing.attributes.social_connections.discord.user_id)
if(goldenId.has(thing.id))
golden.add(thing.attributes.full_name)
}

this.patrons = users;
this.golden = golden;
})
.catch(err => {
return this.log.error({msg: `Error Fetching Patreon Data:`, status: err.response.status, reason: err.response.statusText})
});
}

public getGolden() {
let string = "";
for(const user of this.golden)
string = `${string}${user}, `

string = string.slice(0, (string.length-2));

return string;
}

private async _init() {
fs.readdir('./build/commands/', { withFileTypes: true }, (error, f) => {
if (error) return log.error(error);
Expand All @@ -50,6 +95,13 @@ export default new class Kwako extends Client {
let mongod = await MongoClient.connect(url, { 'useUnifiedTopology': true });
this.db = mongod.db(dbName);
this.log.debug('db initialized')

await this.getPledgeData();
this.log.debug({msg: 'premium enabled'})

this.setInterval(async () => {
await this.getPledgeData();
}, 300000);
}

public async start(token: string) {
Expand Down
9 changes: 7 additions & 2 deletions src/commands/config/addembed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { Message } from 'discord.js';

module.exports.run = async (msg: Message, args: string[]) => {
if ((!msg.member.hasPermission('MANAGE_GUILD'))) return;
let embed = args.join(' ')
embed = JSON.parse(embed)
let embedString = args.join(' ')
let embed = JSON.parse(embedString)

if(!embed.embed) {
embedString = `{"embed":${embedString}}`
embed = JSON.parse(embedString)
}

let sent = await msg.channel.send(embed)

Expand Down
2 changes: 1 addition & 1 deletion src/commands/mod/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports.run = (msg: Message, args: string[]) => {
if (args.length !== 0) {
let channel: any = msg.channel
if (msg.channel.type !== "dm") {
msg.delete().catch(console.error);
msg.delete().catch(Kwako.log.error);
let nb = parseInt(args[0])
msg.channel.bulkDelete(nb)
.then(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/mod/forceskip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Client, Message } from 'discord.js'
import { Message } from 'discord.js'
import music from '../../utils/music'
import { Logger } from 'pino';

module.exports.run = (msg: Message) => {
if (!msg.member.hasPermission('MANAGE_GUILD')) return;
Expand Down
10 changes: 7 additions & 3 deletions src/commands/mod/mute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Kwako from '../../Client'
import { Message, MessageEmbed, TextChannel } from 'discord.js'
const timespan = require("timespan-parser")("min");
//const timespan = require("timespan-parser")("min");
import timespan from '../../utils/timespan';

module.exports.run = async (msg: Message, args:string[], guildConf:any) => {
if (!msg.member.hasPermission('MANAGE_GUILD')) return;
Expand Down Expand Up @@ -55,8 +56,11 @@ async function mute(msg: Message, args: string[], muteRole: string, modLogChanne

args.shift();
let time = args.join(" ")
let timeParsed = await timespan.parse(time, "msec");
let timeParsedString = await timespan.getString(timeParsed, "msec");
let timeParsed = await timespan.parse(time, "msec", msg).catch(() => {return;});
if(!timeParsed || typeof timeParsed !== 'number') return;

let timeParsedString = await timespan.getString(timeParsed, "msec", msg);
if(!timeParsedString || typeof timeParsedString !== 'string') return;

const embed = new MessageEmbed();
embed.setColor('RED')
Expand Down
40 changes: 18 additions & 22 deletions src/commands/profile/setbirthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,28 @@ module.exports.run = async (msg: Message, args: string[], guildConf: any) => {
})
}

if (content.length > 5 || content.length < 3) {
if (content.length > 5 || content.length < 3)
return msg.channel.send({ "embed": { "title": `:x: > **Date format is invalid ! Please enter your birthday like that :\n${guildConf.prefix}setbirthday mm/dd**`, "color": 13632027 } });
}

let date = new Date(content);

if (date) {
let dd = String(date.getDate()).padStart(2, '0');
let mm = String(date.getMonth() + 1).padStart(2, '0');
if(dd === 'NaN' || mm === 'NaN') return;
let today = `${mm}/${dd}`;
await Kwako.db.collection('user').updateOne({ _id: msg.author.id }, { $set: { birthday: today } }, { upsert: true });
const embed = new MessageEmbed();
embed.setAuthor("Your birthday is now set to: ", msg.author.avatarURL({ format: 'png', dynamic: false, size: 128 }));
embed.setTitle(`**${today}**`)
embed.setFooter('(mm/dd)')
embed.setColor('AQUA')

try {
Kwako.log.info({msg: 'setbirthday', author: { id: msg.author.id, name: msg.author.tag }, guild: { id: msg.guild.id, name: msg.guild.name }, date: today});
return msg.channel.send(embed);
} catch (err) {
Kwako.log.error(err);
}
} else
return msg.channel.send({ "embed": { "title": ":x: > **Date format is invalid! Please enter your birthday in mm/dd format.", "color": 13632027 } });
let dd = String(date.getDate()).padStart(2, '0');
let mm = String(date.getMonth() + 1).padStart(2, '0');
if(dd === 'NaN' || mm === 'NaN') return;
let today = `${mm}/${dd}`;
await Kwako.db.collection('user').updateOne({ _id: msg.author.id }, { $set: { birthday: today } }, { upsert: true });
const embed = new MessageEmbed();
embed.setAuthor("Your birthday is now set to: ", msg.author.avatarURL({ format: 'png', dynamic: false, size: 128 }));
embed.setTitle(`**${today}**`)
embed.setFooter('(mm/dd)')
embed.setColor('AQUA')

try {
Kwako.log.info({msg: 'setbirthday', author: { id: msg.author.id, name: msg.author.tag }, guild: { id: msg.guild.id, name: msg.guild.name }, date: today});
return msg.channel.send(embed);
} catch (err) {
Kwako.log.error(err);
}
};

module.exports.help = {
Expand Down
30 changes: 0 additions & 30 deletions src/commands/sleep.ts

This file was deleted.

9 changes: 7 additions & 2 deletions src/commands/suggestions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ module.exports.run = async (msg: Message, args: string[], guildConf: { suggestio
if(!message)
return msg.react('❌');

let channel = await Kwako.channels.fetch(guildConf.suggestionChannel);
let suggestion = await (channel as TextChannel).messages.fetch(message)
let channel = await Kwako.channels.fetch(guildConf.suggestionChannel).catch(() => { return; });
if(!channel)
return msg.react('❌');

let suggestion = await (channel as TextChannel).messages.fetch(message).catch(() => { return; });
if(!suggestion)
return msg.react('❌');

let embed = suggestion.embeds[0];

Expand Down
9 changes: 7 additions & 2 deletions src/commands/suggestions/consider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ module.exports.run = async (msg: Message, args: string[], guildConf: { suggestio
if(!message)
return msg.react('❌');

let channel = await Kwako.channels.fetch(guildConf.suggestionChannel);
let suggestion = await (channel as TextChannel).messages.fetch(message)
let channel = await Kwako.channels.fetch(guildConf.suggestionChannel).catch(() => { return; });
if(!channel)
return msg.react('❌');

let suggestion = await (channel as TextChannel).messages.fetch(message).catch(() => { return; });
if(!suggestion)
return msg.react('❌');

let embed = suggestion.embeds[0];

Expand Down
9 changes: 7 additions & 2 deletions src/commands/suggestions/deny.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ module.exports.run = async (msg: Message, args: string[], guildConf: { suggestio
if(!message)
return msg.react('❌');

let channel = await Kwako.channels.fetch(guildConf.suggestionChannel);
let suggestion = await (channel as TextChannel).messages.fetch(message)
let channel = await Kwako.channels.fetch(guildConf.suggestionChannel).catch(() => { return; });
if(!channel)
return msg.react('❌');

let suggestion = await (channel as TextChannel).messages.fetch(message).catch(() => { return; });
if(!suggestion)
return msg.react('❌');

let embed = suggestion.embeds[0];

Expand Down
9 changes: 7 additions & 2 deletions src/commands/suggestions/implemented.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ module.exports.run = async (msg: Message, args: string[], guildConf: { suggestio
if(!message)
return msg.react('❌');

let channel = await Kwako.channels.fetch(guildConf.suggestionChannel);
let suggestion = await (channel as TextChannel).messages.fetch(message)
let channel = await Kwako.channels.fetch(guildConf.suggestionChannel).catch(() => { return; });
if(!channel)
return msg.react('❌');

let suggestion = await (channel as TextChannel).messages.fetch(message).catch(() => { return; });
if(!suggestion)
return msg.react('❌');

let embed = suggestion.embeds[0];

Expand Down
57 changes: 2 additions & 55 deletions src/commands/utility/anime.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,14 @@
import Kwako from '../../Client'
import { Message, MessageEmbed } from 'discord.js'
import anilistSearch from '../../utils/anilistSearch';
const al = require('anilist-node');
const Anilist = new al();

let number = ['1️⃣','2️⃣','3️⃣','4️⃣','5️⃣'];

module.exports.run = (msg: Message, args: string[]) => {
if (args.length < 1) return;
let req = args.join(' ');
Anilist.search('anime', req, 1, 5).then(async (data: { media: any[]; }) => {
let desc = "";

for(let i = 0; i < data.media.length; i++)
desc = `${desc}${number[i]} ${data.media[i].title.romaji}\n`

let sent = await msg.channel.send({
"embed": {
"title": "🔍",
"description": desc,
"color": 4886754
}
});

for(let i = 0; i < data.media.length; i++)
await sent.react(number[i])

let collected = await sent.awaitReactions((_reaction, user) => (['1️⃣','2️⃣','3️⃣','4️⃣','5️⃣'].includes(_reaction.emoji.name)) && (user.id === msg.author.id), { max: 1, time: 30000 })

sent.delete();
if (collected.first() == undefined) return;

let emote = collected.first().emoji.name

let res = null;
switch (emote) {
case '1️⃣':
if(!data.media[0]) return;
res = data.media[0];
break;

case '2️⃣':
if(!data.media[1]) return;
res = data.media[1];
break;

case '3️⃣':
if(!data.media[2]) return;
res = data.media[2];
break;

case '4️⃣':
if(!data.media[3]) return;
res = data.media[3];
break;

case '5️⃣':
if(!data.media[4]) return;
res = data.media[4];
break;

default:
return;
}
let res = await anilistSearch(msg, data);

if(!res) return msg.react('❌');

Expand Down
Loading

0 comments on commit 2ead8d9

Please sign in to comment.