aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js272
1 files changed, 147 insertions, 125 deletions
diff --git a/index.js b/index.js
index fd9be1e..5d462a6 100644
--- a/index.js
+++ b/index.js
@@ -12,148 +12,170 @@ console.log("["+process.pid+"] running under the name "+process.title)
/**
* Module Imports
*/
-const { Client, Collection, EmbedBuilder, ActivityType, GatewayIntentBits, Partials, Events, SlashCommandBuilder, PermissionsBitField} = require("discord.js");
-const Discord = require('discord.js');
-const dotenv = require("dotenv").config();
-const TOKEN = process.env.TOKEN;
-const path = require("path");
-let db = require("./src/db");
-let util = require("./src/util")
-const client = new Client({
- intents: [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.DirectMessages,
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildBans,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.MessageContent,
- GatewayIntentBits.GuildVoiceStates,
- GatewayIntentBits.GuildMessageReactions,
- GatewayIntentBits.DirectMessages,
- GatewayIntentBits.GuildMembers,
- GatewayIntentBits.DirectMessageReactions,
- GatewayIntentBits.DirectMessageTyping,
- //GatewayIntentBits.GuildPresences
- ],
- partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
-});
+async function main(){
+ const { Client, Collection, EmbedBuilder, ActivityType, GatewayIntentBits, Partials, Events, SlashCommandBuilder, PermissionsBitField} = require("discord.js");
+ const Discord = require('discord.js');
+ const dotenv = require("dotenv").config();
+ const TOKEN = process.env.TOKEN;
+ const path = require("path");
+ let db = require("./src/db");
+ let util = require("./src/util")
+ const { ModalBuilder, REST, Routes, ContextMenuCommandBuilder, ApplicationCommandType } = require('discord.js');
-client.login(TOKEN);
+ const client = new Client({
+ intents: [
+ GatewayIntentBits.Guilds,
+ GatewayIntentBits.GuildMessages,
+ GatewayIntentBits.DirectMessages,
+ GatewayIntentBits.Guilds,
+ GatewayIntentBits.GuildBans,
+ GatewayIntentBits.GuildMessages,
+ GatewayIntentBits.MessageContent,
+ GatewayIntentBits.GuildVoiceStates,
+ GatewayIntentBits.GuildMessageReactions,
+ GatewayIntentBits.DirectMessages,
+ GatewayIntentBits.GuildMembers,
+ GatewayIntentBits.DirectMessageReactions,
+ GatewayIntentBits.DirectMessageTyping,
+ //GatewayIntentBits.GuildPresences
+ ],
+ partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.User]
+ });
-function update_options(scom,options){
- for(let opt of options){
- let autocomplete = opt.autocomplete!=null&&opt.autocomplete!=false;
- switch(opt.type){
- case 'string':
- scom.addStringOption(option => {
+ client.login(TOKEN);
+
+ function update_options(scom,options){
+ for(let opt of options){
+ let autocomplete = opt.autocomplete!=null&&opt.autocomplete!=false;
+ switch(opt.type){
+ case 'string':
+ scom.addStringOption(option => {
+ option.setName(opt.name)
+ .setDescription(opt.desc)
+ .setRequired(opt.required)
+ .setAutocomplete(autocomplete)
+ if(!autocomplete&&opt.choices!=null&&opt.choices!=false){
+ if(typeof opt.choices[0] === 'string'){
+ for(let i in opt.choices) opt.choices[i] = {name:opt.choices[i],value:opt.choices[i]}
+ }
+ option.setChoices(...opt.choices)
+ }
+ return option;
+ })
+ break;
+ case 'bool': case 'boolean':
+ scom.addBooleanOption(option =>
+ option.setName(opt.name)
+ .setDescription(opt.desc)
+ .setRequired(opt.required))
+ break;
+ case 'channel':
+ scom.addChannelOption(option =>
option.setName(opt.name)
.setDescription(opt.desc)
- .setRequired(opt.required)
- .setAutocomplete(autocomplete)
- if(!autocomplete&&opt.choices!=null&&opt.choices!=false){
- if(typeof opt.choices[0] === 'string'){
- for(let i in opt.choices) opt.choices[i] = {name:opt.choices[i],value:opt.choices[i]}
- }
- option.setChoices(...opt.choices)
- }
- return option;
- })
- break;
- case 'bool': case 'boolean':
- scom.addBooleanOption(option =>
+ .setRequired(opt.required))
+ break;
+ case 'user':
+ scom.addUserOption(option =>
+ option.setName(opt.name)
+ .setDescription(opt.desc)
+ .setRequired(opt.required))
+ break;
+ case 'role':
+ scom.addRoleOption(option =>
option.setName(opt.name)
.setDescription(opt.desc)
.setRequired(opt.required))
- break;
- case 'channel':
- scom.addChannelOption(option =>
- option.setName(opt.name)
- .setDescription(opt.desc)
- .setRequired(opt.required))
- break;
- case 'user':
- scom.addUserOption(option =>
- option.setName(opt.name)
- .setDescription(opt.desc)
- .setRequired(opt.required))
- break;
- case 'role':
- scom.addRoleOption(option =>
- option.setName(opt.name)
- .setDescription(opt.desc)
- .setRequired(opt.required))
- break;
- case 'attachment':
- scom.addAttachmentOption(option =>
- option.setName(opt.name)
- .setDescription(opt.desc)
- .setRequired(opt.required))
- break;
- case 'sub':
- scom.addSubcommand(subcommand => {
- subcommand
- .setName(opt.name)
- .setDescription("test")
- return update_options(subcommand, opt.options)
- })
- break;
+ break;
+ case 'attachment':
+ scom.addAttachmentOption(option =>
+ option.setName(opt.name)
+ .setDescription(opt.desc)
+ .setRequired(opt.required))
+ break;
+ case 'sub':
+ scom.addSubcommand(subcommand => {
+ subcommand
+ .setName(opt.name)
+ .setDescription("test")
+ return update_options(subcommand, opt.options)
+ })
+ break;
+ }
+
}
-
+ scom.opt = options
+ return scom;
}
- scom.opt = options
- return scom;
-}
-let commands = []
-let s_commands = []
-fs.readdirSync("./commands/").forEach(folder => {
- fs.readdirSync("./commands/"+folder).forEach(file => {
- if(path.extname(file)==".js"){
- try{
- let com = require("./commands/"+folder+"/"+file)
- com.last_command = {};
- commands.push(com)
- if(com.s_main!=null){
- let scom = new SlashCommandBuilder()
- .setName(com.name.replace(/ /g,'-'))
- .setDescription(com.config.desc)
- if(com.mod_only)
- scom.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
- if(com.s_options!=null){
- update_options(scom,com.s_options);
+ let commands = []
+ let s_commands = []
+ fs.readdirSync("./commands/").forEach(folder => {
+ fs.readdirSync("./commands/"+folder).forEach(file => {
+ if(path.extname(file)==".js"){
+ try{
+ let com = require("./commands/"+folder+"/"+file)
+ com.last_command = {};
+ commands.push(com)
+ if(com.s_main!=null){
+ let scom = new SlashCommandBuilder()
+ .setName(com.name.replace(/ /g,'-'))
+ .setDescription(com.config.desc)
+ if(com.mod_only)
+ scom.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
+ if(com.s_options!=null){
+ update_options(scom,com.s_options);
+ }
+ scom = scom.toJSON()
+ scom.command = com
+ s_commands.push(scom)
}
- scom = scom.toJSON()
- scom.command = com
- s_commands.push(scom)
- }
- } catch (e) {
- if(e.code=="ENOENT"){
- console.log("[ENOENT] missing some config files:( run 'sh buildconfig.sh' to get them\nexiting~")
+ if(com.c_main!=null){
+ let ccom = new ContextMenuCommandBuilder()
+ .setName(com.name.replace(/ /g,'-'))
+ .setType(ApplicationCommandType.User)
+ if(com.mod_only)
+ ccom.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
+ ccom = ccom.toJSON()
+ ccom.command = com
+ s_commands.push(ccom)
+ }
+ } catch (e) {
+ if(e.code=="ENOENT"){
+ console.log("[ENOENT] missing some config files:( run 'sh buildconfig.sh' to get them\nexiting~")
+ process.exit(e.errno)
+ }
+ console.log("["+e.code+"]"+" unexpected error:( something is wrong with the ./commands/*/* files\n****\n")
+ console.log(e)
+
process.exit(e.errno)
}
- console.log("["+e.code+"]"+" unexpected error:( something is wrong with the ./commands/*/* files\n****\n")
- console.log(e)
-
- process.exit(e.errno)
}
- }
+ })
})
-})
-client.env = process.env
-global.commands = commands;
-global.s_commands = s_commands;
-global.recent_messages = [];
+ global.rest = new REST().setToken(TOKEN)
+ global.c_commands = [new ContextMenuCommandBuilder()
+ .setName('test')
+ .setType(ApplicationCommandType.User)
+ .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
+]
+
+ client.env = process.env
+ global.commands = commands;
+ global.s_commands = s_commands;
+ global.recent_messages = [];
-fs.readdirSync("./events/").forEach(file => {
- if(path.extname(file)==".js")
- require("./events/"+file).main(client,Discord)
-})
+ fs.readdirSync("./events/").forEach(file => {
+ if(path.extname(file)==".js")
+ require("./events/"+file).main(client,Discord)
+ })
-try{
- require("./src/webui")
-} catch(e) {
- console.log("failed loading webui:c")
+ try{
+ require("./src/webui")
+ } catch(e) {
+ console.log("failed loading webui:c")
+ }
}
+main()