Skip to content

Commit

Permalink
CRITICAL - Fixes what discord broke and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
zfbx committed Apr 28, 2022
1 parent dbafa83 commit 30c3d44
Show file tree
Hide file tree
Showing 39 changed files with 151 additions and 223 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ typings/

# dotenv environment variables file
.env
test.js
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change log

**7.3.0 - Emergency fix for discord api [2022-04-28]**
- Discord broke everything without warning this fixes that

**7.2.1 - Fixes and support [2022-04-15]**
- update links
- added swedish from ayatollah
Expand Down
44 changes: 0 additions & 44 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ There's currently only 3 permission tiers (mod, admin, god). Permissions are gra
3. Change what is in the quotes `" "` to the permission you want to access the command. ie. `role: "admin",`
4. save and restart the resource or server.

To remove permissions from a command all together where anyone can use them delete both the `default_permission:` and `role:` lines from the command

*Please note that permissions are synced across whole base commands so if you wanted `/money inspect` to be mod+ and `/money add` to be admin+ you'd need to separate them into separate commands to achieve that.*

### Add commands
Expand All @@ -106,7 +104,6 @@ Adding commands can be really simple if you're familiar with javascript but very
3. If you wanted to make it so only admin or god could run your command you'd add the following 2 lines under your description line:
```js
default_permission: false,
role: "admin",
```
Expand Down Expand Up @@ -141,44 +138,3 @@ Adding commands can be really simple if you're familiar with javascript but very
**This resource itself** - Honestly there's so many features and practices being used actively here in commands and utils that you can take note from or in many cases just copy and paste and use so have at it and don't be afraid to break things to help learn more.. as long as you're not working on a live server while you're breaking things ;)


### Add permission levels

By defaults there is mod, admin and god but if you wanted to add another level, for like trial mods, it's actually quite easy to do. In `bot.js`, at the bottom there's a section called `loadDiscordPermissions()`.<br>
It has 2 main parts, The role levels, which look like `const mod = { id:..`<br>
And the role table
```js
this.config.perms = {
"mod": [ mod, admin, god, own ],
"admin": [ admin, god, own ], ...
```
you first would add a role level like:
```js
// You would replace "000000000000000" with the trialmod role id from discord
const trialmod = { id: "000000000000000", type: 1, permission: true };
```
then you would add it to the role table with all the other roles you want to inherit permissions from trialmod:
```js
this.config.perms = {
"trialmod": [ trialmod, mod, admin, god, own ],
"mod": [ mod, admin, god, own ], ...
```

Then in the command files for the commands you want trial mods to be able to access change what was like `role: "mod",` to `role: "trialmod",`, save and restart the resource or server.

**Note:** If you don't add the extra role levels to the trialmod list those roles wont be able to access the commands set with `role: "trialmod"`
**Full example:**
```js
loadDiscordPermissions() {
const mod = { id: this.config.DiscordModRoleId, type: 1, permission: true };
const admin = { id: this.config.DiscordAdminRoleId, type: 1, permission: true };
const god = { id: this.config.DiscordGodRoleId, type: 1, permission: true };
const god2 = { id: "000000000000000000", type: 1, permission: true }; // Added
const own = { id: "142831624868855808", type: 2, permission: true };
this.config.perms = {
"mod": [ mod, admin, god, god2, own ], // changed
"admin": [ admin, god, god2, own ], // changed
"god": [ god, god2, own ], // changed
};
}
```
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ games { "gta5" }
author "zfbx"
description "Discord bot allowlist and more"
repository "https://github.com/zfbx/zdiscord"
version "7.2.1"
version "7.3.0"
license "CC-BY-NC-SA-4.0"
lua54 'yes'

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zdiscord",
"version": "7.2.1",
"version": "7.3.0",
"description": "Advanced Discord Bot Allowlist that's simple to use",
"main": "server.js",
"scripts": {
Expand Down
28 changes: 16 additions & 12 deletions server/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class Bot extends Client {
this.utils.log.assert(!(this.utils.isValidID(this.config.DiscordGodRoleId)), "Your DiscordGodRoleId doesn't seem correct");
this.utils.log.assert(this.config.EnableStaffChatForwarding && !(this.utils.isValidID(this.config.DiscordStaffChannelId)), "Your DiscordStaffChannelId doesn't seem correct");

this.loadDiscordPermissions();

if (this.config.EnableDiscordSlashCommands) this.loadCommands();
this.loadEvents();

Expand Down Expand Up @@ -188,16 +186,22 @@ class Bot extends Client {
return member.roles.cache.map(r => r.id);
}

loadDiscordPermissions() {
const mod = { id: this.config.DiscordModRoleId, type: 1, permission: true };
const admin = { id: this.config.DiscordAdminRoleId, type: 1, permission: true };
const god = { id: this.config.DiscordGodRoleId, type: 1, permission: true };
const own = { id: "142831624868855808", type: 2, permission: true };
this.config.perms = {
"mod": [ mod, admin, god, own ],
"admin": [ admin, god, own ],
"god": [ god, own ],
};
hasPermission(member, level) {
switch (level) {
case "mod":
return (
member.roles.cache.has(this.config.DiscordModRoleId) ||
member.roles.cache.has(this.config.DiscordAdminRoleId) ||
member.roles.cache.has(this.config.DiscordGodRoleId));
case "admin":
return (
member.roles.cache.has(this.config.DiscordAdminRoleId) ||
member.roles.cache.has(this.config.DiscordGodRoleId));
case "god":
return (member.roles.cache.has(this.config.DiscordGodRoleId));
default:
return true;
}
}

}
Expand Down
1 change: 0 additions & 1 deletion server/commands/announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "announcement",
description: "Send in city announcement",
default_permission: false,
role: "mod",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "embed",
description: "Send an embedded (fancy) message in a specified channel",
default_permission: false,
role: "god",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "identifiers",
description: "Get all of a player's identifiers",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "kick",
description: "Kick a player from the city",
default_permission: false,
role: "mod",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/kickall.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "kickall",
description: "Kick every player in the city",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "kill",
description: "kill a player in city",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "message",
description: "direct a message to a specific player",
default_permission: false,
role: "mod",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/players.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const { MessageButton } = require("discord.js");
module.exports = {
name: "players",
description: "Get list of current players in city",
default_permission: false,
role: "mod",

run: async (client, interaction) => {
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "ban",
description: "ban a player",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-clothingmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "clothing-menu",
description: "Give a player the clothing menu",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-gang.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "gang",
description: "Manage player's in-city gang",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "inventory",
description: "Manage player's in-city items",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-jail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "jail",
description: "Manage a player's jail sentence",
default_permission: false,
role: "mod",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "job",
description: "Manage player's in-city job",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "logout",
description: "send a player back to the character selection screen",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-money.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "money",
description: "Manage player's in-city money",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "permissions",
description: "Manage player's in-city permissions",
default_permission: false,
role: "god",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-revive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "revive",
description: "Raise a downed player to full health and stats",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-reviveall.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "revive-all",
description: "Raise all downed players to full health and stats",
default_permission: false,
role: "god",

run: async (client, interaction, args) => {
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "time",
description: "set city time",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-user-checkonline.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "onlinecheck",
type: "USER",
default_permission: false,
role: "mod",

run: async (client, interaction, args) => {
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const vehicleStates = {
module.exports = {
name: "vehicle",
description: "Give user a vehicle with a fixed plate",
default_permission: false,
role: "god",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/qb-weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "weather",
description: "Manage city weather",
default_permission: false,
role: "admin",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const { MessageButton } = require("discord.js");
module.exports = {
name: "resource",
description: "Manage server resources / scripts",
default_permission: false,
role: "god",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const Buffer = require("buffer").Buffer;
module.exports = {
name: "screenshot",
description: "Screenshot player's POV",
default_permission: false,
role: "god",

options: [
Expand Down
6 changes: 2 additions & 4 deletions server/commands/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
module.exports = {
name: "server",
description: "Get FiveM and Discord Stats",
// default_permission: false,
// role: "mod",

run: async (client, interaction) => {
if (client.isRolePresent(interaction.member, [client.config.DiscordModRoleId, client.config.DiscordAdminRoleId, client.config.DiscordGodRoleId])) {
Expand All @@ -34,15 +32,15 @@ module.exports = {
**Channels:** ${interaction.guild.channels.cache.filter((chan) => chan.type === "GUILD_TEXT").size}
**Members:** ${interaction.guild.memberCount}${getWhitelisted(client, interaction)}
**Owner:** <@${interaction.guild.ownerId}> (${interaction.guild.ownerId})`, true)
.setFooter({ text: `${GetCurrentResourceName()} by zfbx` });
.setFooter({ text: "zdiscord by zfbx" });
return interaction.reply({ embeds: [ embed ] });
} else {
const embed = new client.Embed()
.setThumbnail(interaction.guild.iconURL({ format: "png", size: 512 }))
.addField(client.config.FiveMServerName, `**Server IP:** ${client.config.FiveMServerIP}
**Uptime:** ${(GetGameTimer() / 1000 / 60).toFixed(2)} minutes
**Players:** ${GetNumPlayerIndices()}/${GetConvar("sv_maxClients", "Unknown")}`, false)
.setFooter({ text: `${GetCurrentResourceName()} by zfbx` });
.setFooter({ text: "zdiscord by zfbx" });
return interaction.reply({ embeds: [ embed ] });
}
},
Expand Down
1 change: 0 additions & 1 deletion server/commands/teleport.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "teleport",
description: "teleport a player",
default_permission: false,
role: "mod",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/teleportall.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "teleport-all",
description: "teleport everyone",
default_permission: false,
role: "god",

options: [
Expand Down
1 change: 0 additions & 1 deletion server/commands/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
module.exports = {
name: "whitelist",
description: "Manage whitelist",
default_permission: false,
role: "god",

options: [
Expand Down
4 changes: 4 additions & 0 deletions server/events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module.exports = {
if (!command) {
return interaction.reply({ content: "An error has occurred ", ephemeral: true }).catch((error) => client.utils.log.handler("error", error));
}
if (!client.hasPermission(interaction.member, command.role)) {
return interaction.reply({ content: "You don't have permission to use this command", ephemeral: true }).catch();
}

const args = {};
for (const option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
Expand Down
Loading

0 comments on commit 30c3d44

Please sign in to comment.