aboutsummaryrefslogtreecommitdiff
path: root/commands/util/help.js
blob: a8d5cb4493403d3e65f64ad602dce3dcc70f5c7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const fs = require('fs')
const path = require("path");
const { EmbedBuilder,ActionRowBuilder,ButtonBuilder,ButtonStyle  } = require("discord.js");
let config_loc = __filename+".json"
let settings = require("../../src/settings")
let config = JSON.parse(fs.readFileSync(config_loc))

//get command names
let command_names = ["help"]
fs.readdirSync(path.join(__dirname+"/..")).forEach(folder => {
    fs.readdirSync(path.join(__dirname+"/../"+folder)).forEach(file => {
        if(path.extname(file)==".js"){
            if(path.join(__dirname+"/../"+folder+"/"+file)!=__filename){
                let info = require("../"+folder+"/"+file)
                //let commands = info.command.length>3?info.command.slice(0,3).join(",")+"...":info.command.join(",")
                command_names.push(info.name)
            }
        
        }
    })
})
//

module.exports = {
    name : "help",
    command: ["help"],
    mod_only: false,
    config:config,
    config_loc:config_loc,
    async main (client,Discord,message,args){
        this.exec(client,{message:message,specify:args[0]})
    },
    s_options:[{type:"string",name:"command",desc:"command to be specified",required:false,autocomplete:false,choices:command_names}],
    async s_main(client,Discord,interaction){
        this.exec(client,{message:interaction,specify:interaction.options.getString("command")})
    },
    async exec(client,param){
        if(param.specify!=null){
            let info = null
            fs.readdirSync(path.join(__dirname+"/..")).forEach(folder => {
                fs.readdirSync(path.join(__dirname+"/../"+folder)).forEach(file => {
                    if(path.extname(file)==".js"){
                        let tinfo = require("../"+folder+"/"+file)
                        if(tinfo.name==param.specify||tinfo.command.includes(param.specify))
                            info=tinfo
                    }
                })
            })
            if(info==null)
                return param.message.reply({content:"command not found:c",ephemeral: true})
            let restricted = info.config.restricted.length==0?"undefined":info.config.restricted.join(",")
            let restrict = info.config.restrict.length==0?"undefined":info.config.restrict.join(",")
            const embed = new EmbedBuilder()
                .setTitle(info.name)
                .setColor(settings.defaultColor)
                .addFields([{
                    name:"commands/subcommands",
                    value:info.command.join(",")
                },{
                    name:"description",
                    value:  info.config.desc == undefined ? "undefined" : info.config.desc
                },{
                    name:"usage",
                    value:  info.config.usage == undefined ? "undefined" : info.config.usage
                },{
                    name:"misc",
                    value:"cooldown: "+info.config.cooldown+", restricted channels: ["+restricted+"], restrict to channels: ["+restrict+"], "+(info.s_main!=null?"supports slash commands":"does not support slash commands")
                }])
                param.message.reply({embeds:[embed]})
            return
        }
        //message.reply("not done yet:( give ans-chan some hugs and headpats for faster development")
        let pages = []
        let page = 0
        fs.readdirSync(path.join(__dirname+"/..")).forEach(folder => {
            const embed = new EmbedBuilder()
                .setTitle(folder)
                .setColor(settings.defaultColor)
            let count = 0;
            fs.readdirSync(path.join(__dirname+"/../"+folder)).forEach(file => {
                if(path.extname(file)==".js"){
                    count++;
                    let info = require("../"+folder+"/"+file)
                    let commands = info.command.length>3?info.command.slice(0,3).join(",")+"...":info.command.join(",")
                    embed.addFields([{
                        name:info.name + " [" + commands + "]",
                        value:info.config.desc
                    }])
                    /*page.push({
                        name:info.name,
                        subcommands:info.command,
                        desc:info.desc,
                        cooldown:cooldown
                    })*/

                }
            })
            embed.setFooter({text:"use `sns help {command}` to get more info • "+count+" items"})
            pages.push(embed)
        })
        const last = new ButtonBuilder()
            .setCustomId('last')
            .setEmoji('⬅️')
            .setStyle(ButtonStyle.Primary)
        const next = new ButtonBuilder()
            .setCustomId('next')
            .setEmoji('➡️')
            .setStyle(ButtonStyle.Primary)
        const row = new ActionRowBuilder()
            .addComponents(last,next);
        let mess = await param.message.reply({embeds:[pages[page]],components:[row]})
        async function rec_edit(mess,page){
            const collectorFilter = i => i.user.id === param.message.author.id;
            try {
                const confirmation = await mess.awaitMessageComponent({ filter: collectorFilter, time: 60000000 });
                if(confirmation.customId == "next"){
                    if(page+1<pages.length)
                        page++;
                    else
                        page=0;
                    mess.edit({embeds:[pages[page]]})
                    rec_edit(mess,page)
                    confirmation.deferUpdate()
                }
                if(confirmation.customId == "last"){
                    if(page-1>=0)
                        page--;
                    else
                        page=pages.length-1;
                    mess.edit({embeds:[pages[page]]})
                    rec_edit(mess,page)
                    confirmation.deferUpdate()
                }
            } catch (e) {
                
            }
        }
        await rec_edit(mess,page)
    }
}