/[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 256 by rakin, Mon Jul 29 17:29:14 2024 UTC revision 393 by rakin, Mon Jul 29 17:29:59 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 { formatDistance } 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 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 formatDistance(new Date(), new Date(seconds));      return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }));
122  }  }
123    
124    
# Line 150  export function escapeRegex(string: stri Line 168  export function escapeRegex(string: stri
168  export function timeSince(date: number) {  export function timeSince(date: number) {
169      // const seconds = Math.floor((Date.now() - date) / 1000);      // const seconds = Math.floor((Date.now() - date) / 1000);
170      // return timeProcess(seconds) + ' ago';      // return timeProcess(seconds) + ' ago';
171      return formatDistance(new Date(), new Date(date), { addSuffix: true });      return formatDistanceToNowStrict(new Date(date), { addSuffix: true });
172  }  }
173    
174  export async function download(url: string, path: string, headers?: AxiosRequestHeaders) {    export async function download(url: string, path: string, headers?: AxiosRequestHeaders) {  

Legend:
Removed from v.256  
changed lines
  Added in v.393

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26