Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify-fail-count for users #18

Merged
merged 6 commits into from
Jan 9, 2021
Merged
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
18 changes: 12 additions & 6 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require("dotenv").config();

const { join } = require("path");
const Discord = require("discord.js");
const getFiles = require("./getFiles");
const remind = require("./remind");
const addRole = require("./utils/addRole");
const verify = require("./verify");
const user = require("./utils/usersHandlers");

const bot = new Discord.Client();
bot.commands = new Discord.Collection();

// Greet a new user
bot.on("guildMemberAdd", (member) => {
bot.on("guildMemberAdd", async (member) => {
const channel = member.guild.channels.cache.find(
(ch) => ch.name === "welcome"
);
Expand All @@ -27,7 +26,12 @@ bot.on("guildMemberAdd", (member) => {
)
.setFooter("Use !help command to know more about me ");
channel.send(welcomeEmbed);
verify(bot, member);

// adding the member to the "users" collection in DB
const exists = await user.existsInUsers(member.id);
if (exists === false) {
await user.add(member.id);
}
});

bot.on("ready", async () => {
Expand All @@ -45,11 +49,13 @@ bot.on("ready", async () => {
setInterval(() => remind(bot), 3000000);

bot.on("message", (message) => {
if (message.channel.type === "dm") return;

const args = message.content.trim().split(/\r\n|\r|\n| +/);
const command = args.shift().toLowerCase();

if (command === "!verify") {
verify(bot, message.author);
if (message.channel.id === process.env.VERIFY_CHANNEL_ID) {
if (command === "!verify") verify(bot, message.author);
return;
}

Expand Down
15 changes: 15 additions & 0 deletions models/user.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mongoose = require("mongoose");

const userSchema = new mongoose.Schema(
{
discordId: { type: String, required: true },
failCount: { type: Number, required: true },
cfHandle: { type: String, required: false },
},
{
timestamps: true,
collection: "users",
}
);

module.exports = new mongoose.model("User", userSchema);
Loading