Skip to content

Commit

Permalink
Verify-fail-count for users (#18)
Browse files Browse the repository at this point in the history
* feat: Ban user on 3 failed verification attempts

- created user schema
- ban handler

* [Fix]:Use !verify only in #verify channel

- blocked DM
- removed unnecessary return statements

* [Fix]: Check if "user" exists to tackle rejoin

* [Fix]: user.existsInUsers was never getting called without await.

* [Fix]: Made husky work(hopefully).

* [Fix]: Minor change

Co-authored-by: Utkarsh <[email protected]>
  • Loading branch information
hemant2132 and utkarsh261 authored Jan 9, 2021
1 parent 4cabea1 commit 122ab36
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 104 deletions.
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

0 comments on commit 122ab36

Please sign in to comment.