-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/saiteja-madha/discord-js-bot …
…into main
- Loading branch information
Showing
45 changed files
with
1,178 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"printWidth": 120 | ||
"printWidth": 120, | ||
"bracketSpacing": true, | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const { Command } = require("@src/structures"); | ||
const { maxWarnings, maxWarnAction } = require("@schemas/guild-schema"); | ||
const { Message } = require("discord.js"); | ||
const { getRoleByName } = require("@utils/guildUtils"); | ||
|
||
module.exports = class MaxWarn extends Command { | ||
constructor(client) { | ||
super(client, { | ||
name: "maxwarn", | ||
description: "set max warnings configuration", | ||
command: { | ||
enabled: true, | ||
minArgsCount: 1, | ||
subcommands: [ | ||
{ | ||
trigger: "limit <number>", | ||
description: "set max warnings a member can receive before taking an action", | ||
}, | ||
{ | ||
trigger: "action <MUTE|KICK|BAN>", | ||
description: "set action to performed after receiving maximum warnings", | ||
}, | ||
], | ||
category: "ADMIN", | ||
userPermissions: ["ADMINISTRATOR"], | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* @param {Message} message | ||
* @param {string[]} args | ||
*/ | ||
async messageRun(message, args, invoke, prefix) { | ||
const input = args[0].toUpperCase(); | ||
|
||
// Limit configuration | ||
if (input === "LIMIT") { | ||
const max = args[1]; | ||
if (isNaN(max) || Number.parseInt(max) < 1) | ||
return message.reply("Max Warnings must be a valid number greater than 0"); | ||
|
||
await maxWarnings(message.guildId, max); | ||
message.channel.send(`Configuration saved! Maximum warnings is set to ${max}`); | ||
} | ||
|
||
// Action | ||
else if (input === "ACTION") { | ||
const action = args[1]?.toUpperCase(); | ||
|
||
if (!action) message.reply("Please choose an action. Action can be `Mute`/`Kick`/`Ban`"); | ||
if (!["MUTE", "KICK", "BAN"].includes(action)) | ||
return message.reply("Not a valid action. Action can be `Mute`/`Kick`/`Ban`"); | ||
|
||
if (action === "MUTE") { | ||
let mutedRole = getRoleByName(message.guild, "muted"); | ||
if (!mutedRole) { | ||
return message.reply(`Muted role doesn't exist in this guild. Use \`${prefix}mute setup\` to create one`); | ||
} | ||
|
||
if (!mutedRole.editable) { | ||
return message.reply( | ||
"I do not have permission to move members to `Muted` role. Is that role below my highest role?" | ||
); | ||
} | ||
} | ||
|
||
await maxWarnAction(message.guildId, action); | ||
message.channel.send(`Configuration saved! Max Warnings action is set to ${action}`); | ||
} | ||
|
||
// send usage | ||
else { | ||
return this.sendUsage(message.channel, prefix, invoke, "Incorrect Arguments"); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { Command } = require("@src/structures"); | ||
const { Message, Util, MessageEmbed } = require("discord.js"); | ||
|
||
module.exports = class EmojiInfo extends Command { | ||
constructor(client) { | ||
super(client, { | ||
name: "emojiinfo", | ||
description: "shows info about an emoji", | ||
command: { | ||
enabled: true, | ||
usage: "<emoji>", | ||
minArgsCount: 1, | ||
aliases: ["emoji"], | ||
category: "INFORMATION", | ||
}, | ||
slashCommand: { | ||
enabled: false, | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* @param {Message} message | ||
* @param {string[]} args | ||
*/ | ||
async messageRun(message, args) { | ||
const emoji = args[0]; | ||
let custom = Util.parseEmoji(emoji); | ||
if (!custom.id) return message.channel.send("This is not a valid guild emoji"); | ||
|
||
let url = `https://cdn.discordapp.com/emojis/${custom.id}.${custom.animated ? "gif?v=1" : "png"}`; | ||
|
||
const embed = new MessageEmbed() | ||
.setColor(this.client.config.EMBED_COLORS.BOT_EMBED) | ||
.setAuthor("Emoji Info") | ||
.setDescription( | ||
`**Id:** ${custom.id}\n` + `**Name:** ${custom.name}\n` + `**Animated:** ${custom.animated ? "Yes" : "No"}` | ||
) | ||
.setImage(url); | ||
|
||
return message.channel.send({ embeds: [embed] }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const { Command } = require("@src/structures"); | ||
const { Message, MessageEmbed, ContextMenuInteraction } = require("discord.js"); | ||
const { EMBED_COLORS, EMOJIS } = require("@root/config"); | ||
const { getProfile } = require("@schemas/profile-schema"); | ||
const { getSettings } = require("@schemas/guild-schema"); | ||
const { resolveMember } = require("@utils/guildUtils"); | ||
const { getUser } = require("@schemas/user-schema"); | ||
|
||
module.exports = class Profile extends Command { | ||
constructor(client) { | ||
super(client, { | ||
name: "profile", | ||
description: "shows members profile", | ||
cooldown: 5, | ||
command: { | ||
enabled: true, | ||
category: "INFORMATION", | ||
}, | ||
contextMenu: { | ||
enabled: true, | ||
type: "USER", | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* @param {Message} message | ||
* @param {string[]} args | ||
*/ | ||
async messageRun(message, args) { | ||
const target = (await resolveMember(message, args[0])) || message.member; | ||
const embed = await buildEmbed(message.guild, target); | ||
message.channel.send({ embeds: [embed] }); | ||
} | ||
|
||
/** | ||
* @param {ContextMenuInteraction} interaction | ||
*/ | ||
async contextRun(interaction) { | ||
const target = (await interaction.guild.members.fetch(interaction.targetId)) || interaction.member; | ||
const embed = await buildEmbed(interaction.guild, target); | ||
interaction.followUp({ embeds: [embed] }); | ||
} | ||
}; | ||
|
||
const buildEmbed = async (guild, target) => { | ||
const { user } = target; | ||
const settings = await getSettings(guild); | ||
const profile = await getProfile(guild.id, user.id); | ||
const userData = await getUser(user.id); | ||
|
||
return new MessageEmbed() | ||
.setThumbnail(user.displayAvatarURL()) | ||
.setColor(EMBED_COLORS.BOT_EMBED) | ||
.addField("User Tag", user.tag, true) | ||
.addField("ID", user.id, true) | ||
.addField("Discord Registered", user.createdAt.toDateString(), false) | ||
.addField("Cash", `${userData?.coins || 0} ${EMOJIS.CURRENCY}`, true) | ||
.addField("Bank", `${userData?.bank || 0} ${EMOJIS.CURRENCY}`, true) | ||
.addField("Net Worth", `${(userData?.coins || 0) + (userData?.bank || 0)}${EMOJIS.CURRENCY}`, true) | ||
.addField("Messages*", `${settings.ranking.enabled ? (profile?.messages || 0) + " " : "Not Tracked"}`, true) | ||
.addField("XP*", `${settings.ranking.enabled ? (profile?.xp || 0) + " " : "Not Tracked"}`, true) | ||
.addField("Level*", `${settings.ranking.enabled ? (profile?.level || 0) + " " : "Not Tracked"}`, true) | ||
.addField("Strikes*", (profile?.strikes || 0) + " ", true) | ||
.addField("Warnings*", (profile?.warnings || 0) + " ", true) | ||
.addField("Reputation", `${userData?.reputation?.received || 0}`, true) | ||
.addField("Avatar-URL", user.displayAvatarURL({ format: "png" })) | ||
.setFooter("Fields marked (*) are guild specific"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { Command } = require("@src/structures"); | ||
const { Message, MessageAttachment } = require("discord.js"); | ||
const { API, EMBED_COLORS } = require("@root/config"); | ||
const { getProfile, getTop100 } = require("@schemas/profile-schema"); | ||
const { downloadImage } = require("@utils/httpUtils"); | ||
const { getSettings } = require("@schemas/guild-schema"); | ||
const { resolveMember } = require("@utils/guildUtils"); | ||
|
||
module.exports = class Rank extends Command { | ||
constructor(client) { | ||
super(client, { | ||
name: "rank", | ||
description: "shows members rank in this server", | ||
cooldown: 5, | ||
command: { | ||
enabled: true, | ||
category: "INFORMATION", | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* @param {Message} message | ||
* @param {string[]} args | ||
*/ | ||
async messageRun(message, args) { | ||
const target = (await resolveMember(message, args[0])) || message.member; | ||
const { user } = target; | ||
|
||
const settings = await getSettings(message.guild); | ||
if (!settings.ranking.enabled) return message.channel.send("Ranking is disabled on this server"); | ||
|
||
const profile = await getProfile(message.guildId, user.id); | ||
if (!profile) return message.channel.send(`${user.tag} is not ranked yet!`); | ||
|
||
const lb = await getTop100(message.guildId); | ||
let pos = -1; | ||
lb.forEach((doc, i) => { | ||
if (doc.member_id == target.id) { | ||
pos = i + 1; | ||
} | ||
}); | ||
|
||
const xpNeeded = profile.level * profile.level * 100; | ||
|
||
const url = new URL(`${API.IMAGE_API}/utils/rank-card`); | ||
url.searchParams.append("name", user.username); | ||
url.searchParams.append("discriminator", user.discriminator); | ||
url.searchParams.append("avatar", user.displayAvatarURL({ format: "png", size: 128 })); | ||
url.searchParams.append("currentxp", profile.xp); | ||
url.searchParams.append("reqxp", xpNeeded); | ||
url.searchParams.append("level", profile.level); | ||
url.searchParams.append("barcolor", EMBED_COLORS.BOT_EMBED); | ||
url.searchParams.append("status", message.member.presence.status.toString()); | ||
if (pos !== -1) url.searchParams.append("rank", pos); | ||
|
||
const rankCard = await downloadImage(url.href); | ||
if (!rankCard) return message.reply("Failed to generate rank-card"); | ||
|
||
const attachment = new MessageAttachment(rankCard, "rank.png"); | ||
message.channel.send({ files: [attachment] }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.