How to use the eris.Constants.Permissions function in eris

To help you get started, we’ve selected a few eris examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dragory / ZeppelinBot / backend / src / plugins / Slowmode.ts View on Github external
async applyBotSlowmodeToUserId(channel: GuildChannel & TextChannel, userId: string) {
    // Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
    const existingOverride = channel.permissionOverwrites.get(userId);
    const newDeniedPermissions =
      (existingOverride ? existingOverride.deny : 0) | ErisConstants.Permissions.sendMessages;
    const newAllowedPermissions =
      (existingOverride ? existingOverride.allow : 0) & ~ErisConstants.Permissions.sendMessages;

    try {
      await channel.editPermission(userId, newAllowedPermissions, newDeniedPermissions, "member");
    } catch (e) {
      const user = this.bot.users.get(userId) || new UnknownUser({ id: userId });

      if (e instanceof DiscordRESTError && e.code === 50013) {
        logger.warn(
          `Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${channel.id}) on server ${this.guild.name} (${this.guildId})`,
        );
        this.logs.log(LogType.BOT_ALERT, {
          body: `Missing permissions to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
          user: stripObjectToScalars(user),
          channel: stripObjectToScalars(channel),
github Dragory / ZeppelinBot / backend / src / plugins / Slowmode.ts View on Github external
async applyBotSlowmodeToUserId(channel: GuildChannel & TextChannel, userId: string) {
    // Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
    const existingOverride = channel.permissionOverwrites.get(userId);
    const newDeniedPermissions =
      (existingOverride ? existingOverride.deny : 0) | ErisConstants.Permissions.sendMessages;
    const newAllowedPermissions =
      (existingOverride ? existingOverride.allow : 0) & ~ErisConstants.Permissions.sendMessages;

    try {
      await channel.editPermission(userId, newAllowedPermissions, newDeniedPermissions, "member");
    } catch (e) {
      const user = this.bot.users.get(userId) || new UnknownUser({ id: userId });

      if (e instanceof DiscordRESTError && e.code === 50013) {
        logger.warn(
          `Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${channel.id}) on server ${this.guild.name} (${this.guildId})`,
        );
        this.logs.log(LogType.BOT_ALERT, {
          body: `Missing permissions to apply bot slowmode to {userMention(user)} in {channelMention(channel)}`,
          user: stripObjectToScalars(user),
          channel: stripObjectToScalars(channel),
        });
      } else {
github erisaaa / erisa / defaults / commands / src / Context.ts View on Github external
hasPermission(permission: string, target: PermissionTargets = PermissionTargets.Self): boolean {
        if (!Object.keys(Constants.Permissions).includes(permission)) {
            if (this.client.extensions.logger) this.client.extensions.logger.dispatch('warn', `Unknown permission "${permission}"`);
            return true;
        }

        switch (target) {
            case PermissionTargets.Self:
                return this.channel.permissionsOf(this._client.user.id).has(permission);
            case PermissionTargets.Author:
                return this.channel.permissionsOf(this.author.id).has(permission);
            case PermissionTargets.Both:
                return this.hasPermission(permission) && this.hasPermission(permission, PermissionTargets.Author);
            default:
                throw new Error(`Unknown target: ${target}`);
        }
    }
}
github AugustArchive / Maika / old / util / permissions.js View on Github external
static gather(permission) {
        if (!permission)
            return this.gather(0);

        if (typeof permission === 'number' && permission >= 0)
            return permission;

        if (permission instanceof Array)
            return permission.map(p => this.gather(p)).reduce((previous, p) => previous | p, 0);

        if (typeof permission === 'string')
            return Constants.Permissions[permission];

        throw new RangeError('Invalid permission bitfield.');
    }