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

Polls, fetch user by ID, tidying, patched a couple of bugs #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"discord.js": "github:discordjs/discord.js",
"dotenv": "^8.2.0",
"mongoose": "^5.8.3",
"mongoose-float": "^1.0.4",
"ms": "^2.1.2"
}
}
19 changes: 19 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"UserSchema": {
"default": {
"id": "",
"guild": "",
"profile": {
"git": "",
"dotfiles": "",
"description": ""
}
}
},
"confirmDialogues": {
"timeout": 20000
},
"showcaseChannel": "635625917623828520",
"logChannel": "673003438635876382",
"ricingChannel": "635625925748457482"
}
103 changes: 58 additions & 45 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const Discord = require("discord.js");

require("dotenv").config();
require("./utilities/messageAuthorDisplayName.js");
require("./utilities/messageColor.js");
require("./utilities/messageFetchUser.js");
Expand All @@ -21,19 +21,19 @@ module.exports = class extends Discord.Client {
restTimeOffset: 2500,
restSweepInterval: 30,
ws: {
compress: false
compress: false,
},
disabledEvents: [
"TYPING_START",
"PRESENCE_UPDATE",
"USER_UPDATE",
"WEBHOOKS_UPDATE",
"MESSAGE_REACTION_ADD"
]
"MESSAGE_REACTION_ADD",
],
});

//Settings file
this.settings = require("./settings.json");
this.settings = require("../settings.json");

//Database schema for per-guild colour role list
this.RoleSchema = require("./models/roleSchema.js");
Expand All @@ -44,66 +44,79 @@ module.exports = class extends Discord.Client {
this.commands = require("./commands.js");

//Import message handler only once
this.message = (message) =>
require("./events/message.js")(this, message, Discord);

this.ready = () => require("./events/ready.js")(this);

this.messageDelete = (message) =>
require("./events/messageDelete.js")(this, message, Discord);

this.guildMemberAdd = (member) =>
require("./events/guildMemberAdd.js")(this, member, Discord);
this.message = message =>
require("./events/message.js")(
this,
message,
Discord
);

this.ready = () =>
require("./events/ready.js")(this);

this.messageDelete = message =>
require("./events/messageDelete.js")(
this,
message,
Discord
);

this.guildMemberAdd = member =>
require("./events/guildMemberAdd.js")(
this,
member,
Discord
);

this.showcase = (client, message) =>
require("./events/showcase.js")(client, message, Discord);

this.sendLog = (message) =>
this.channels.cache.get(this.settings.logChannel).send(message);

this.commandHelp = (name) =>
require("./utilities/miFetchCommandHelp.js")(this, name);

this.handleMessageScore = (message) =>
require("./events/handleMessageScore.js")(this, message);

this.log = (log) =>
require("./events/handleLog.js")(this, log, Discord);

this.createUserSchema = (user, guild) =>
require("./createUserSchema.js")(this, user, guild);

this.on("userScoreUpdate", (scoreUpdate) =>
require("./events/userScoreUpdate.js")(this, scoreUpdate)
);
require("./events/showcase.js")(
client,
message,
Discord
);

this.sendLog = message =>
this.channels.cache
.get(this.settings.logChannel)
.send(message);

this.commandHelp = name =>
require("./utilities/miFetchCommandHelp.js")(
this,
name
);

this
//Events
.on("ready", () => this.ready())

.on("reconnect", () => this.ready())

.on("message", (message) => this.message(message))
.on("message", message => this.message(message))

.on("guildMemberAdd", (member) => this.guildMemberAdd(member))
.on("guildMemberAdd", member =>
this.guildMemberAdd(member)
)

.on("messageDelete", (message) => this.messageDelete(message));
.on("messageDelete", message =>
this.messageDelete(message)
);

//Connect to MongoDB
require("mongoose").connect(process.env.MONGO, {
useNewUrlParser: true,
useUnifiedTopology: true
useUnifiedTopology: true,
});

process
.on("unhandledRejection", (error) => {
this.log(error.message);
.on("unhandledRejection", error => {
console.log(error);
})
.on("uncaughtException", (error) => {
this.log(error.message);
.on("uncaughtException", error => {
console.log(error);
})
.on("warning", (error) => {
this.log(error.message);
.on("warning", error => {
console.log(error);
});

this.login(process.env.TOKEN);
Expand Down
34 changes: 21 additions & 13 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,27 @@ module.exports = new Discord.Collection()

.set("setgit", require("./commands/gitEdit.js"))

.set("rep", require("./commands/userRep.js"))
.set("thanks", require("./commands/userRep.js"))

.set("desc", require("./commands/descriptionEdit.js"))
.set("description", require("./commands/descriptionEdit.js"))
.set("setdesc", require("./commands/descriptionEdit.js"))
.set("setdescription", require("./commands/descriptionEdit.js"))
.set("editdesc", require("./commands/descriptionEdit.js"))
.set("editdescription", require("./commands/descriptionEdit.js"))
.set(
"description",
require("./commands/descriptionEdit.js")
)
.set(
"setdesc",
require("./commands/descriptionEdit.js")
)
.set(
"setdescription",
require("./commands/descriptionEdit.js")
)
.set(
"editdesc",
require("./commands/descriptionEdit.js")
)
.set(
"editdescription",
require("./commands/descriptionEdit.js")
)

.set("profile", require("./commands/userInfo.js"))
.set("userinfo", require("./commands/userInfo.js"))
Expand All @@ -56,8 +68,4 @@ module.exports = new Discord.Collection()

.set("serverinfo", require("./commands/guildInfo.js"))
.set("guildinfo", require("./commands/guildInfo.js"))
.set("server", require("./commands/guildInfo.js"))

.set("editscore", require("./commands/scoreEdit.js"))

.set("score", require("./commands/scoreView.js"));
.set("server", require("./commands/guildInfo.js"));
2 changes: 1 addition & 1 deletion src/commands/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ exports.meta = {
operatorOnly: false,
name: "avatar",
usage: `${process.env.PREFIX || "!"}pfp <user>`,
description: "Shows avatar of @mentioned user or self"
description: "Shows avatar of @mentioned user or self",
};
28 changes: 18 additions & 10 deletions src/commands/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.run = async (client, message, args, Discord) => {
client.UserSchema.findOne(
{
id: user.id,
guild: message.guild.id
guild: message.guild.id,
},
async (error, config) => {
if (error) {
Expand All @@ -19,7 +19,9 @@ exports.run = async (client, message, args, Discord) => {

if (
user !== message.author &&
!message.member.hasPermission("MANAGE_GUILD")
!message.member.hasPermission(
"MANAGE_GUILD"
)
) {
return message.channel.embed(
`**${message.authorDisplayName}**, you cannot clear the profile of other users`
Expand All @@ -39,22 +41,26 @@ exports.run = async (client, message, args, Discord) => {

try {
var response = await message.channel.awaitMessages(
(m) =>
m =>
["yes", "y", "no", "n"].includes(
m.content.toLowerCase()
) && m.author === message.author,
{
max: 1,
time: client.settings.confirmDialogues.timeout,
errors: ["time"]
time:
client.settings.confirmDialogues
.timeout,
errors: ["time"],
}
);
} catch (err) {
return message.channel.embed(
`**${message.authorDisplayName}**, cancelled selection, missing or invalid input`
);
}
response = response.first().content.toLowerCase();
response = response
.first()
.content.toLowerCase();

if (["no", "n"].includes(response)) {
return message.channel.embed(
Expand All @@ -65,12 +71,14 @@ exports.run = async (client, message, args, Discord) => {
config.profile = {
git: "",
dots: "",
description: ""
description: "",
};

message.channel.embed(`Cleared **profile** of user **${user}**`);
message.channel.embed(
`Cleared **profile** of user **${user}**`
);

config.save().catch((e) => console.error(e));
config.save().catch(e => console.error(e));
}
);
};
Expand All @@ -79,5 +87,5 @@ exports.meta = {
operatorOnly: true,
name: "user clear",
usage: `${process.env.PREFIX || "!"}purge <user>`,
description: "Clears custom entries on user profile"
description: "Clears custom entries on user profile",
};
Loading