-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.ts
More file actions
105 lines (96 loc) · 4.32 KB
/
index.ts
File metadata and controls
105 lines (96 loc) · 4.32 KB
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
import {api, opendiscord, utilities} from "#opendiscord"
import * as discord from "discord.js"
//DECLARATION
declare module "#opendiscord-types" {
export interface ODPluginManagerIds_Default {
"example-command":api.ODPlugin
}
export interface ODSlashCommandManagerIds_Default {
"example-command:ping":api.ODSlashCommand
}
export interface ODTextCommandManagerIds_Default {
"example-command:ping":api.ODTextCommand
}
export interface ODCommandResponderManagerIds_Default {
"example-command:ping":{source:"slash"|"text",params:{},workers:"example-command:ping"|"example-command:logs"},
}
export interface ODMessageManagerIds_Default {
"example-command:ping-message":{source:"slash"|"text"|"other",params:{},workers:"example-command:ping-message"},
}
export interface ODEmbedManagerIds_Default {
"example-command:ping-embed":{source:"slash"|"text"|"other",params:{},workers:"example-command:ping-embed"},
}
}
//REGISTER SLASH COMMAND
opendiscord.events.get("onSlashCommandLoad").listen((slash) => {
slash.add(new api.ODSlashCommand("example-command:ping",{
name:"ping",
description:"Pong!",
type:discord.ApplicationCommandType.ChatInput,
contexts:[discord.InteractionContextType.Guild],
integrationTypes:[discord.ApplicationIntegrationType.GuildInstall]
}))
})
//REGISTER TEXT COMMAND
opendiscord.events.get("onTextCommandLoad").listen((text) => {
const generalConfig = opendiscord.configs.get("opendiscord:general")
text.add(new api.ODTextCommand("example-command:ping",{
name:"ping",
prefix:generalConfig.data.prefix,
dmPermission:false,
guildPermission:true
}))
})
//REGISTER HELP MENU
opendiscord.events.get("onHelpMenuComponentLoad").listen((menu) => {
menu.get("opendiscord:extra").add(new api.ODHelpMenuCommandComponent("example-command:ping",0,{
slashName:"ping",
textName:"ping",
slashDescription:"Test Command!",
textDescription:"Test Command!"
}))
})
//REGISTER EMBED BUILDER
opendiscord.events.get("onEmbedBuilderLoad").listen((embeds) => {
embeds.add(new api.ODEmbed("example-command:ping-embed"))
embeds.get("example-command:ping-embed").workers.add(
new api.ODWorker("example-command:ping-embed",0,(instance,params,source,cancel) => {
const generalConfig = opendiscord.configs.get("opendiscord:general")
instance.setTitle("Pong!")
instance.setColor(generalConfig.data.mainColor)
instance.setDescription("You've now used the example command!")
})
)
})
//REGISTER MESSAGE BUILDER
opendiscord.events.get("onMessageBuilderLoad").listen((messages) => {
messages.add(new api.ODMessage("example-command:ping-message"))
messages.get("example-command:ping-message").workers.add(
new api.ODWorker("example-command:ping-message",0,async (instance,params,source,cancel) => {
instance.addEmbed(await opendiscord.builders.embeds.getSafe("example-command:ping-embed").build(source,{}))
})
)
})
//REGISTER COMMAND RESPONDER
opendiscord.events.get("onCommandResponderLoad").listen((commands) => {
const generalConfig = opendiscord.configs.get("opendiscord:general")
commands.add(new api.ODCommandResponder("example-command:ping",generalConfig.data.prefix,"ping"))
commands.get("example-command:ping").workers.add([
new api.ODWorker("example-command:ping",0,async (instance,params,source,cancel) => {
const {guild,channel,user} = instance
if (!guild){
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(source,{channel,user}))
return cancel()
}
await instance.reply(await opendiscord.builders.messages.getSafe("example-command:ping-message").build(source,{}))
}),
new api.ODWorker("example-command:logs",-1,(instance,params,source,cancel) => {
opendiscord.log(instance.user.displayName+" used the 'ping' command!","plugin",[
{key:"user",value:instance.user.username},
{key:"userid",value:instance.user.id,hidden:true},
{key:"channelid",value:instance.channel.id,hidden:true},
{key:"method",value:source}
])
})
])
})