-
Notifications
You must be signed in to change notification settings - Fork 1
/
SlashCtx.js
144 lines (133 loc) · 5.61 KB
/
SlashCtx.js
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
141
142
143
144
const { Message, TextChannel, CommandInteraction, MessageOptions, User, Guild, GuildMember, MessageAttachment, MessageActionRow, MessageButton, MessageEmbed } = require("discord.js");
const Client = require('./Client');
class Context {
/** @param {CommandInteraction} interaction */
constructor(interaction, client) {
/**
* @type {Client}
* @returns {Client}
*/
this.client = client;
this.slash = true;
/** @type {CommandInteraction}*/
this.interaction = interaction;
/**@type {TextChannel}*/
this.channel = interaction.channel || null;
/** @type {Guild}*/
this.guild = interaction.guild || null;
/** @type {GuildMember}*/
this.me = this.guild.me || null;
/** @type {User}*/
this.author = interaction.user || null;
/** @type {GuildMember}*/
this.member = interaction.member || null;
this.command = this.client.CommandHandler.commands.get(interaction.commandName);
this.db = this.client.db;
};
/**
* @param {'string' | 'message' | 'boolean' | 'number' | 'user' | 'member' | 'role' | 'channel'} type
* @param {{ name: string, all?: false, getBooleanFromFlags?: false }} opt
* @description Option.all arguman verilerini Array olarak verir. Ama sadece Message Command üzerinde çalışır.
*/
find(type, opt) {
return this.getArgs(type, opt.name);
}
emoji(emojiname) {
return this.client.Emoji.get(emojiname);
}
/**
* @name sendMessage
* @param {MessageOptions|MessageEmbed|MessageActionRow|MessageAttachment|MessageButton|String|Number} args
* @returns Message
*/
send(...arg) {
let Embeds = [], ActionRows = [], Attachments = [], text = '', _Object;
args.forEach(e => {
if (typeof e == 'string' || typeof e == 'number') return text += `${e}`;
if (e instanceof MessageEmbed) return Embeds.push(e);
if (e instanceof MessageButton) {
if (ActionRows.length >= 1) {
ActionRows[0] = ActionRows[0].addComponents(e);
} else {
let nMAR = new MessageActionRow().addComponents(e)
ActionRows.push(nMAR);
}
return;
}
if (e instanceof MessageActionRow) return ActionRows.push(e);
if (e instanceof MessageAttachment) return Attachments.push(e);
if (typeof e == 'object') return _Object = e;
});
if (_Object)
return this.channel.send(_Object);
else
return this.channel.send({
content: text == '' ? undefined: text,
embeds: Embeds,
components: ActionRows,
files: Attachments
});
};
/** @param {'string' | 'message' | 'get' | 'boolean' | 'number' | 'user' | 'member' | 'role' | 'channel' | 'subCommand'} type */
getArgs(type, name) {
switch(type) {
case "string":
return this.interaction.options.getString(name);
case "message":
return this.interaction.options.getMessage(name);
case "get":
return this.interaction.options.get(name);
case "boolean":
return this.interaction.options.getBoolean(name);
case "number":
return this.interaction.options.getNumber(name);
case "user":
return this.interaction.options.getUser(name);
case "member":
return this.interaction.options.getMember(name);
case "role":
return this.interaction.options.getRole(name);
case "channel":
return this.interaction.options.getChannel(name);
case "subCommand":
return this.interaction.options.getSubcommand();
}
}
/**
* @name replyMessage
* @param {MessageOptions|MessageEmbed|MessageActionRow|MessageAttachment|MessageButton|String|Number} args
* @returns Message
*/
reply(...args) {
let Embeds = [], ActionRows = [], Attachments = [], text = '', _Object, _Hide = false;
args.forEach(Value => {
if (typeof Value == 'string' || typeof Value == 'number') return text += `${Value}`;
if (Value instanceof MessageEmbed) return Embeds.push(Value);
if (Value instanceof MessageButton) {
if (ActionRows.length >= 1) {
ActionRows[0] = ActionRows[0].addComponents(Value);
} else {
let nMAR = new MessageActionRow().addComponents(Value)
ActionRows.push(nMAR);
}
return;
}
if (Value instanceof MessageActionRow) return ActionRows.push(Value);
if (Value instanceof MessageAttachment) return Attachments.push(Value);
if (Value?.hideReply) return _Hide = true;
if (typeof Value == 'object') return _Object = Value;
});
if (_Object)
return this.interaction.reply(_Object);
else
return this.interaction.reply({
content: text == '' ? undefined: text,
embeds: Embeds,
components: ActionRows,
files: Attachments,
allowedMentions: { repliedUser: false },
ephemeral: _Hide
});
};
};
module.exports = Context;