/[sudobot]/trunk/src/utils/util.ts
ViewVC logotype

Diff of /trunk/src/utils/util.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 262 by rakin, Mon Jul 29 17:29:16 2024 UTC revision 422 by rakin, Mon Jul 29 17:30:09 2024 UTC
# Line 1  Line 1 
1    /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20  import fs from 'fs';  import fs from 'fs';
21  import DiscordClient from '../client/Client';  import DiscordClient from '../client/Client';
22  import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js';  import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js';
23  import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios';  import Axios, { AxiosRequestHeaders } from 'axios';
24  import { formatDistanceToNowStrict } from 'date-fns';  import { formatDistanceToNowStrict, formatDuration, intervalToDuration } from 'date-fns';
 import { Snippet } from '../services/SnippetManager';  
25    
26  export function parseEmbedsInString(content: string) {  export function parseEmbedsInString(content: string) {
27      const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g);      const embedExpressions = content.matchAll(/embed\:(\{[^\n]+\})/g);
# Line 62  export function shouldNotModerate(client Line 80  export function shouldNotModerate(client
80    
81      const role = client.config.props[member.guild.id].admin;      const role = client.config.props[member.guild.id].admin;
82    
83      return member.roles.cache.has(role);      return role && role.trim() !== '' && member.roles.cache.has(role);
84  }  }
85    
86  export async function hasPermission(client: DiscordClient, member: GuildMember, msg: Message | CommandInteraction | ContextMenuInteraction, mod: GuildMember | null, error: string = "You don't have permission to moderate this user") {  export async function hasPermission(client: DiscordClient, member: GuildMember, msg: Message | CommandInteraction | ContextMenuInteraction, mod: GuildMember | null, error: string = "You don't have permission to moderate this user") {
# Line 72  export async function hasPermission(clie Line 90  export async function hasPermission(clie
90          m = msg.member! as GuildMember;          m = msg.member! as GuildMember;
91      }      }
92            
93      if (member.id !== m.id && member.roles.highest?.position >= m.roles.highest?.position) {      if (member.id === m.id || member.roles.highest?.position >= m.roles.highest?.position) {
94          if (msg instanceof Interaction && msg.deferred) {          if (msg instanceof Interaction && msg.deferred) {
95              await msg.editReply({              await msg.editReply({
96                  embeds: [                  embeds: [
# Line 100  export async function hasPermission(clie Line 118  export async function hasPermission(clie
118  }  }
119    
120  export function timeProcess(seconds: number) {  export function timeProcess(seconds: number) {
121      return formatDistanceToNowStrict(new Date(seconds));      return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }));
122  }  }
123    
124    

Legend:
Removed from v.262  
changed lines
  Added in v.422

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26