/[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 196 by rakin, Mon Jul 29 17:28:58 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 } 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            await msg.reply({
25                embeds: [
26                    new MessageEmbed()
27                    .setColor('#f14a60')
28                    .setDescription(`:x: ${error}`)
29                ]
30            });
31    
32            return false;
33        }
34    
35        return true;
36    }
37    
38  export function timeProcess(seconds: number) {        export function timeProcess(seconds: number) {      
39      let interval = seconds / (60 * 60 * 24 * 30 * 365);      let interval = seconds / (60 * 60 * 24 * 30 * 365);
40    
# Line 79  export async function deleteFile(path: s Line 113  export async function deleteFile(path: s
113  export function random(arr: Array <any>) {  export function random(arr: Array <any>) {
114      let index = Math.floor(Math.random() * arr.length);      let index = Math.floor(Math.random() * arr.length);
115      return arr[index];      return arr[index];
 }  
116    }
117    
118    export function fill(length: number, string: string, token: string = ' ') {
119        let safe = 0;
120    
121        if (length < string.length)
122            return string;
123    
124        const diff = length - string.length;
125    
126        for (let i = 1; i <= diff; i++, safe++) {
127            if (safe >= 500)
128                break;        
129    
130            string += ' ';
131        }  
132    
133        return string;
134    }
135    
136    export function green(string: string) {
137        return '\u001b[1;32m' + string + '\u001b[0m';
138    }
139    
140    export function yellow(string: string) {
141        return '\u001b[1;33m' + string + '\u001b[0m';
142    }
143    
144    export function red(string: string) {
145        return '\u001b[1;31m' + string + '\u001b[0m';
146    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26