/[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 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 210 by rakin, Mon Jul 29 17:29:02 2024 UTC
# Line 1  Line 1 
1  import fs from 'fs';  import fs from 'fs';
2    import DiscordClient from '../client/Client';
3    import { GuildMember, Message, CommandInteraction, MessageEmbed, ContextMenuInteraction, Interaction } from 'discord.js';
4  import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios';  import Axios, { AxiosRequestHeaders, HeadersDefaults } from 'axios';
5    
6    export function shouldNotModerate(client: DiscordClient, member: GuildMember) {
7        if (!client.config.props[member.guild.id].admin) {
8            return false;
9        }
10    
11        const role = client.config.props[member.guild.id].admin;
12    
13        return member.roles.cache.has(role);
14    }
15    
16    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") {
17        let m = mod;
18        
19        if (!m) {
20            m = msg.member! as GuildMember;
21        }
22        
23        if (member.roles.highest?.position >= m.roles.highest?.position) {
24            if (msg instanceof Interaction && msg.deferred) {
25                await msg.editReply({
26                    embeds: [
27                        new MessageEmbed()
28                        .setColor('#f14a60')
29                        .setDescription(`:x: ${error}`)
30                    ]
31                });
32    
33                return false;
34            }
35    
36            await msg.reply({
37                embeds: [
38                    new MessageEmbed()
39                    .setColor('#f14a60')
40                    .setDescription(`:x: ${error}`)
41                ]
42            });
43    
44            return false;
45        }
46    
47        return true;
48    }
49    
50  export function timeProcess(seconds: number) {        export function timeProcess(seconds: number) {      
51      let interval = seconds / (60 * 60 * 24 * 30 * 365);      let interval = seconds / (60 * 60 * 24 * 30 * 365);
52    
# Line 79  export async function deleteFile(path: s Line 125  export async function deleteFile(path: s
125  export function random(arr: Array <any>) {  export function random(arr: Array <any>) {
126      let index = Math.floor(Math.random() * arr.length);      let index = Math.floor(Math.random() * arr.length);
127      return arr[index];      return arr[index];
 }  
128    }
129    
130    export function fill(length: number, string: string, token: string = ' ') {
131        let safe = 0;
132    
133        if (length < string.length)
134            return string;
135    
136        const diff = length - string.length;
137    
138        for (let i = 1; i <= diff; i++, safe++) {
139            if (safe >= 500)
140                break;        
141    
142            string += ' ';
143        }  
144    
145        return string;
146    }
147    
148    export function green(string: string) {
149        return '\u001b[1;32m' + string + '\u001b[0m';
150    }
151    
152    export function yellow(string: string) {
153        return '\u001b[1;33m' + string + '\u001b[0m';
154    }
155    
156    export function red(string: string) {
157        return '\u001b[1;31m' + string + '\u001b[0m';
158    }

Legend:
Removed from v.51  
changed lines
  Added in v.210

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26