Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
v1.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
iwa authored Jul 1, 2020
2 parents bc25b2e + 1a6858d commit 48ee250
Show file tree
Hide file tree
Showing 15 changed files with 689 additions and 97 deletions.
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "06:00"
timezone: Universal
open-pull-requests-limit: 10
target-branch: dev
assignees:
- iwa
labels:
- dependencies
ignore:
- dependency-name: popyt
versions:
- ">= 3.1.a"
- "< 3.2"
- dependency-name: popyt
versions:
- ">= 3.3.a"
- "< 3.4"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ node_modules/

# Q-Bot internals
image/
download/
.env

# TypeScript artifacts
build/

# npm lockfile
package-lock.json
package-lock.json

gcs-key.json
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "q-bot",
"version": "1.7.1",
"version": "1.7.2",
"description": "Discord Bot for Qumu's Discord Server",
"main": "build/index.js",
"scripts": {
Expand All @@ -14,6 +14,7 @@
"license": "ISC",
"dependencies": {
"@discordjs/opus": "^0.3.2",
"@google-cloud/storage": "^5.1.1",
"@types/ejs": "^3.0.4",
"@types/mongodb": "^3.5.25",
"@types/node": "^14.0.14",
Expand Down
18 changes: 12 additions & 6 deletions src/commands/approve.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { Client, Message, TextChannel, MessageEmbed } from 'discord.js';
import utilities from '../utils/utilities';
import { Db } from 'mongodb';

module.exports.run = async (bot: Client, msg: Message, args: string[]) => {
module.exports.run = async (bot: Client, msg: Message, args: string[], db: Db) => {
if (!utilities.isMod(msg) && msg.author.id != process.env.IWA && msg.author.id != process.env.QUMU) return;

let message = await db.collection('suggestions').findOne({ _id: parseInt(args[0]) });
if(!message)
return msg.react('❌');

let channel = await bot.channels.fetch(process.env.SUGGESTIONTC);
let suggestion = await (channel as TextChannel).messages.fetch(args[0])
let suggestion = await (channel as TextChannel).messages.fetch(message.msg)

let embed = suggestion.embeds[0];

embed.setTitle("Suggestion: Approved")
embed.setColor(10019146)

let req = "\n";
if(args.length >= 2) {
args.shift()
let req = args.join(' ');
embed.addField(`Reason, by ${msg.author.username}`, req)
req = args.join(' ');
}
let desc = embed.description;
embed.setDescription(`${desc}\n\n**✅ Approved by ${msg.author.username}**\n${req}`);

let reactions = suggestion.reactions.resolve('👀');
let users = await reactions.users.fetch();
Expand All @@ -38,5 +44,5 @@ module.exports.run = async (bot: Client, msg: Message, args: string[]) => {

module.exports.help = {
name: 'approve',
usage: "?approve (uid) [reason]",
usage: "?approve (id) [reason]",
};
4 changes: 2 additions & 2 deletions src/commands/bulk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Client, Message } from 'discord.js'
import staff from '../utils/staff';

module.exports.run = (bot: Client, msg: Message, args: string[]) => {
staff.bulk(msg, args);
module.exports.run = (bot: Client, msg: Message) => {
staff.bulk(msg);
};

module.exports.help = {
Expand Down
16 changes: 11 additions & 5 deletions src/commands/consider.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { Client, Message, TextChannel, MessageEmbed } from 'discord.js';
import utilities from '../utils/utilities';
import { Db } from 'mongodb';

module.exports.run = async (bot: Client, msg: Message, args: string[]) => {
module.exports.run = async (bot: Client, msg: Message, args: string[], db: Db) => {
if (!utilities.isMod(msg) && msg.author.id != process.env.IWA && msg.author.id != process.env.QUMU) return;

let message = await db.collection('suggestions').findOne({ _id: parseInt(args[0]) });
if(!message)
return msg.react('❌');

let channel = await bot.channels.fetch(process.env.SUGGESTIONTC);
let suggestion = await (channel as TextChannel).messages.fetch(args[0])
let suggestion = await (channel as TextChannel).messages.fetch(message.msg)

let embed = suggestion.embeds[0];

embed.setTitle("Suggestion: Considered")
embed.setColor(14598460)

let req = "\n";
if(args.length >= 2) {
args.shift()
let req = args.join(' ');
embed.addField(`Reason, by ${msg.author.username}`, req)
req = args.join(' ');
}
let desc = embed.description;
embed.setDescription(`${desc}\n\n**🤔 Considered by ${msg.author.username}**\n${req}`);

let reactions = suggestion.reactions.resolve('👀');
let users = await reactions.users.fetch();
Expand Down
16 changes: 11 additions & 5 deletions src/commands/deny.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { Client, Message, TextChannel, MessageEmbed } from 'discord.js';
import utilities from '../utils/utilities';
import { Db } from 'mongodb';

module.exports.run = async (bot: Client, msg: Message, args: string[]) => {
module.exports.run = async (bot: Client, msg: Message, args: string[], db: Db) => {
if (!utilities.isMod(msg) && msg.author.id != process.env.IWA && msg.author.id != process.env.QUMU) return;

let message = await db.collection('suggestions').findOne({ _id: parseInt(args[0]) });
if(!message)
return msg.react('❌');

let channel = await bot.channels.fetch(process.env.SUGGESTIONTC);
let suggestion = await (channel as TextChannel).messages.fetch(args[0])
let suggestion = await (channel as TextChannel).messages.fetch(message.msg)

let embed = suggestion.embeds[0];

embed.setTitle("Suggestion: Denied")
embed.setColor(14956363)

let req = "\n";
if(args.length >= 2) {
args.shift()
let req = args.join(' ');
embed.addField(`Reason, by ${msg.author.username}`, req)
req = args.join(' ');
}
let desc = embed.description;
embed.setDescription(`${desc}\n\n**❌ Denied by ${msg.author.username}**\n${req}`);

let reactions = suggestion.reactions.resolve('👀');
let users = await reactions.users.fetch();
Expand Down
43 changes: 43 additions & 0 deletions src/commands/implemented.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Client, Message, TextChannel, MessageEmbed } from 'discord.js';
import utilities from '../utils/utilities';
import { Db } from 'mongodb';

module.exports.run = async (bot: Client, msg: Message, args: string[], db: Db) => {
if (!utilities.isMod(msg) && msg.author.id != process.env.IWA && msg.author.id != process.env.QUMU) return;

let message = await db.collection('suggestions').findOne({ _id: parseInt(args[0]) });
if(!message)
return msg.react('❌');

let channel = await bot.channels.fetch(process.env.SUGGESTIONTC);
let suggestion = await (channel as TextChannel).messages.fetch(message.msg)

let embed = suggestion.embeds[0];

embed.setColor(4289797)

let desc = embed.description;
embed.setDescription(`${desc}\n\n**✅ Implemented by ${msg.author.username}**\n\n`);

let reactions = suggestion.reactions.resolve('👀');
let users = await reactions.users.fetch();

let embedDM = new MessageEmbed();
embedDM.setTitle(`Suggestion "${embed.description.slice(0, 10)}..." has been updated!`);
embedDM.setDescription(`Check it out [here](${suggestion.url})`)

for(const user of users.array()) {
if(!user.bot) {
await user.send(embedDM).catch(() => {return});
console.log('yo')
}
}

await suggestion.edit(embed);
return msg.react('✅');
};

module.exports.help = {
name: 'implemented',
usage: "?implemented (id)",
};
4 changes: 2 additions & 2 deletions src/commands/utility/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ setTimeout(() => {
let mod = {
"embed": {
"title": "**⚔️ Mods**",
"description": "`?forceskip`\n`?bulk (amount of messages to delete)`\n`?mute (mention someone) (length, eg. '5d 1h 20m 35s')`\n?approve (suggestion UID) [reason]\n?consider (suggestion UID) [reason]\n?deny (suggestion UID) [reason]",
"description": "`?forceskip`\n`?mute (mention someone) (length, eg. '5d 1h 20m 35s')`\n?approve (suggestion ID) [reason]\n?implemented (suggestion ID)\n?consider (suggestion ID) [reason]\n?deny (suggestion ID) [reason]",
"color": 4886754
}
}
Expand All @@ -74,7 +74,7 @@ module.exports.help = {
};

async function sendHelp(msg: Message) {
if (utilities.isMod(msg) == true || msg.author.id == process.env.QUMU)
if (utilities.isMod(msg) == true || msg.author.id == process.env.QUMU || msg.author.id == process.env.IWA)
try {
await msg.author.send(member)
await msg.author.send(mod)
Expand Down
35 changes: 0 additions & 35 deletions src/commands/utility/suggest.ts

This file was deleted.

59 changes: 59 additions & 0 deletions src/events/messages/suggestion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Client, Message, MessageEmbed, TextChannel, MessageAttachment } from 'discord.js'
import { Db, MongoClient } from 'mongodb';

export default async function suggestion (bot: Client, msg: Message, mongod:MongoClient, db: Db) {
let req = msg.cleanContent;
let channel = await bot.channels.fetch(process.env.SUGGESTIONTC);

let embed = new MessageEmbed();
if(msg.attachments.first()) {
await msg.react('🔄');
await download(msg.attachments.first().proxyURL, `download/${msg.attachments.first().name}`);
await uploadFile(`${msg.attachments.first().name}`).catch(console.error);
embed.setThumbnail(`https://cdn.iwa.sh/attachment/${msg.attachments.first().name}`);
req = `${req}\n\n[📂attachment link](https://cdn.iwa.sh/attachment/${msg.attachments.first().name})`
}
embed.setDescription(req);
embed.setAuthor(msg.author.username, msg.author.avatarURL({ format: 'png', dynamic: false, size: 128 }))

let counter = await db.collection('suggestions').findOne({ _id: 'counter' });
if(!counter) {
await db.collection('suggestions').insertOne({ _id: 'counter', count: 0 });
counter = { _id: 'counter', count: 0 };
}

await db.collection('suggestions').updateOne({ _id: 'counter' }, { $inc: { count: 1 }});
embed.setFooter(`#${counter.count+1}`);

await msg.delete();
let sent = await (channel as TextChannel).send(embed);
await db.collection('suggestions').insertOne({ _id: counter.count+1, msg: sent.id });

await mongod.close();

await sent.react('✅');
await sent.react('❌');
return sent.react('👀');
};

const fs = require('fs');
const request = require('request');

async function download(uri: any, filename: any) {
let bar = new Promise((resolve, reject) => {
request.head(uri, function(err: any, res: { headers: { [x: string]: any; }; }, body: any) {
request(uri).pipe(fs.createWriteStream(filename)).on('close', () => { resolve() });
});
});
return bar;
};

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();

async function uploadFile(filename: string) {
await storage.bucket('cdn.iwa.sh').upload(`download/${filename}`, {
gzip: false,
destination: `attachment/${filename}`,
});
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const levels = require('../lib/levels.json');

import cooldown from './events/messages/cooldown';
import ready from './events/ready';
import suggestion from './events/messages/suggestion';


// Imports commands from the 'commands' folder
Expand Down Expand Up @@ -68,6 +69,9 @@ bot.on('message', async (msg: Discord.Message) => {
let db = mongod.db(dbName);
let date: string = new Date().toISOString().slice(0, 10)

if (msg.channel.id == process.env.SUGGESTIONTC)
return suggestion(bot, msg, mongod, db);

if (!msg.content.startsWith(process.env.PREFIX))
return cooldown.exp(msg, mongod, db, date);

Expand Down
18 changes: 16 additions & 2 deletions src/utils/letmein.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,22 @@ export default async function letmein(msg: Message, levels: any, db: Db) {

let user: any = await db.collection('user').findOne({ '_id': { $eq: msg.author.id } });
if (user) {
let lvl = await utilities.levelInfo(user.exp);
if (lvl.level != 0) await msg.member.roles.add(levels[lvl.level].id);
let lvl = utilities.levelInfo(user.exp);
if(lvl.level >= 2) {
await msg.member.roles.add('720723902212603935').catch(console.error);
} else if(lvl.level >= 5) {
await msg.member.roles.remove('720723902212603935').catch(console.error);
await msg.member.roles.add('720723905370783864').catch(console.error);
} else if(lvl.level >= 10) {
await msg.member.roles.remove('720723905370783864').catch(console.error);
await msg.member.roles.add('720723908436951101').catch(console.error);
} else if(lvl.level >= 15) {
await msg.member.roles.remove('720723908436951101').catch(console.error);
await msg.member.roles.add('720723911247003729').catch(console.error);
} else if(lvl.level >= 20) {
await msg.member.roles.remove('720723911247003729').catch(console.error);
await msg.member.roles.add('720723913444818974').catch(console.error);
}
await db.collection('user').updateOne({ _id: msg.author.id }, { $set: { hidden: false } });
}

Expand Down
Loading

0 comments on commit 48ee250

Please sign in to comment.