@tryty/easydc-js 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ // Contoh fitur v1.1: modal, autocomplete, menu klik-kanan, poll, event baru.
2
+ // Dimuat dengan: bot.loadCommands('./examples/advanced')
3
+ module.exports = [
4
+ // --- Modal: slash command membuka form, lalu handler membaca isinya ---
5
+ {
6
+ type: 'slash',
7
+ name: 'lapor',
8
+ description: 'Kirim laporan lewat form',
9
+ code: `
10
+ $addModal[lapor_form;Form Laporan]
11
+ $addTextInput[judul;Judul;short;Ringkas saja;true;3;50]
12
+ $addTextInput[isi;Isi laporan;paragraph]
13
+ `,
14
+ },
15
+ {
16
+ type: 'modal',
17
+ customId: 'lapor_form',
18
+ code: '$ephemeral Terima kasih $username! Judul: $modalValue[judul] | Isi: $modalValue[isi]',
19
+ },
20
+
21
+ // --- Autocomplete ---
22
+ {
23
+ type: 'slash',
24
+ name: 'buah',
25
+ description: 'Pilih buah',
26
+ options: [{ name: 'nama', description: 'Nama buah', autocomplete: true }],
27
+ code: 'Kamu memilih $option[nama]',
28
+ },
29
+ {
30
+ type: 'autocomplete',
31
+ command: 'buah',
32
+ option: 'nama',
33
+ code: `
34
+ $addChoice[Apel;apel]
35
+ $addChoice[Jeruk;jeruk]
36
+ $addChoice[Mangga;mangga]
37
+ `,
38
+ },
39
+
40
+ // --- Menu klik-kanan ---
41
+ { type: 'contextMenu', menu: 'user', name: 'Lihat Profil', code: '$ephemeral Profil: $targetName (ID $targetID)' },
42
+ { type: 'contextMenu', menu: 'message', name: 'Laporkan', code: '$ephemeral Pesan "$targetContent" dari $targetName dilaporkan.' },
43
+
44
+ // --- Poll + moderasi dengan pelindung izin ---
45
+ { name: 'vote', code: '$poll[Makan apa hari ini?;24;false;Nasi;Mie;Roti]' },
46
+ {
47
+ name: 'unban',
48
+ code: `
49
+ $onlyPerms[BanMembers;❌ Kamu butuh izin BanMembers.]
50
+ $argsCheck[1;Format: !unban <userID>]
51
+ $if[$isBanned[$message[1]]==false]User itu tidak sedang di-ban.$stop$endif
52
+ $unban[$message[1];Dicabut oleh $username]
53
+ ✅ Ban dicabut.
54
+ `,
55
+ },
56
+
57
+ // --- Event baru ---
58
+ { type: 'voiceJoin', code: '🔊 $username masuk ke $targetName' },
59
+ { type: 'memberBan', code: '🔨 $targetName di-ban dari server.' },
60
+ ];
@@ -0,0 +1,100 @@
1
+ // Jalankan: TOKEN=token_bot_kamu node examples/basic.js
2
+ const { Bot } = require('easydc-js'); // saat dicoba dari folder ini: require('../src')
3
+
4
+ const bot = new Bot({
5
+ token: process.env.TOKEN,
6
+ prefix: '!',
7
+ owners: [], // isi ID Discord kamu agar $onlyOwner berfungsi
8
+ timezone: 'Asia/Jakarta',
9
+ status: { text: '!help', type: 'Listening' },
10
+ });
11
+
12
+ // Variabel yang disimpan permanen di database (harus dideklarasikan + nilai awal)
13
+ bot.variables({ uang: 100 });
14
+
15
+ bot.command({ name: 'ping', code: '🏓 Pong! $ping ms' });
16
+
17
+ bot.command({
18
+ name: 'help',
19
+ code: `
20
+ $title[Daftar perintah]
21
+ $description[\`!ping\` \`!uang\` \`!kerja\` \`!ulang\` \`!ban\`]
22
+ $color[blurple]
23
+ `,
24
+ });
25
+
26
+ bot.command({
27
+ name: 'uang',
28
+ code: '💰 $username punya $numberSeparator[$getUserVar[uang];.] koin',
29
+ });
30
+
31
+ bot.command({
32
+ name: 'kerja',
33
+ code: `
34
+ $cooldown[1m;Kamu capek, istirahat %time% lagi.]
35
+ $let[gaji;$random[10;50]]
36
+ $setUserVar[uang;$math[$getUserVar[uang]+$get[gaji]]]
37
+ Kamu kerja dan dapat $get[gaji] koin! Total: $getUserVar[uang]
38
+ `,
39
+ });
40
+
41
+ bot.command({
42
+ name: 'ulang',
43
+ code: `
44
+ $argsCheck[2;Format: !ulang <kata> <jumlah>]
45
+ $repeat[$message[1] ;$message[2]]
46
+ `,
47
+ });
48
+
49
+ // Contoh if / else
50
+ bot.command({
51
+ name: 'cek',
52
+ code: `
53
+ $if[$isAdmin==true]
54
+ Kamu admin 👑
55
+ $elseif[$hasRole[ISI_ID_ROLE]==true]
56
+ Kamu anggota 🙂
57
+ $else
58
+ Kamu tamu 👋
59
+ $endif
60
+ `,
61
+ });
62
+
63
+ // Moderasi: SELALU lindungi dengan $onlyPerms
64
+ bot.command({
65
+ name: 'ban',
66
+ code: `
67
+ $onlyPerms[BanMembers;❌ Kamu butuh izin BanMembers.]
68
+ $onlyBotPerms[BanMembers;❌ Bot tidak punya izin BanMembers.]
69
+ $argsCheck[1;Format: !ban @user alasan]
70
+ $ban[$mentioned[1];Dibanned oleh $username]
71
+ ✅ Berhasil ban <@$mentioned[1]>
72
+ `,
73
+ });
74
+
75
+ // Slash command
76
+ bot.slashCommand({
77
+ name: 'halo',
78
+ description: 'Menyapa seseorang',
79
+ options: [{ name: 'nama', description: 'Siapa yang disapa', type: 'string', required: true }],
80
+ code: 'Halo, $option[nama]! 👋',
81
+ });
82
+
83
+ // Tombol
84
+ bot.command({
85
+ name: 'tombol',
86
+ code: `
87
+ Tekan tombolnya:
88
+ $addButton[Klik aku;primary;klik_1]
89
+ $addButton[Website;link;https://discord.js.org]
90
+ `,
91
+ });
92
+ bot.button({ customId: 'klik_*', code: '$ephemeral Kamu menekan `$customID`' });
93
+
94
+ // Event
95
+ bot.onMemberJoin('Selamat datang $mention di **$serverName**! 🎉');
96
+
97
+ bot.connect().then(() => console.log('Bot sedang login...')).catch((e) => {
98
+ console.error(e.message);
99
+ process.exit(1);
100
+ });
@@ -0,0 +1,6 @@
1
+ // Command dari file: dimuat dengan bot.loadCommands('./examples/commands')
2
+ module.exports = {
3
+ name: 'ping',
4
+ aliases: ['p'],
5
+ code: `🏓 Pong! Latensi: $ping ms | Aktif: $uptime`,
6
+ };
@@ -0,0 +1,28 @@
1
+ // Satu file boleh berisi banyak command (array) dan jenis berbeda (type).
2
+ module.exports = [
3
+ {
4
+ name: 'profil',
5
+ code: `
6
+ $cooldown[5s;Tunggu %time% ya.]
7
+ $newEmbed
8
+ $title[Profil $username[$mentioned[1;yes]]]
9
+ $thumbnail[$userAvatar[$mentioned[1;yes]]]
10
+ $color[#5865F2]
11
+ $addField[Uang;💰 $numberSeparator[$getUserVar[uang;$mentioned[1;yes]];.];true]
12
+ $addField[Bergabung;<t:$round[$math[$userCreatedAt[$mentioned[1;yes]]/1000]]:D>;true]
13
+ $footer[Diminta oleh $username]
14
+ `,
15
+ },
16
+ {
17
+ type: 'slash',
18
+ name: 'halo',
19
+ description: 'Menyapa seseorang',
20
+ options: [{ name: 'nama', description: 'Nama yang disapa', type: 'string', required: true }],
21
+ code: `Halo, $option[nama]! 👋`,
22
+ },
23
+ {
24
+ type: 'button',
25
+ customId: 'klik_*',
26
+ code: `$ephemeral Kamu menekan tombol \`$customID\`.`,
27
+ },
28
+ ];
package/index.d.ts ADDED
@@ -0,0 +1,129 @@
1
+ import type { Client } from 'discord.js';
2
+
3
+ export interface BotOptions {
4
+ token?: string;
5
+ prefix?: string | string[];
6
+ mentionPrefix?: boolean;
7
+ ignoreBots?: boolean;
8
+ owners?: string | string[];
9
+ intents?: 'default' | 'all' | Array<string | number>;
10
+ syncSlash?: boolean;
11
+ slashGuild?: string | null;
12
+ timezone?: string;
13
+ allowedMentions?: object;
14
+ debug?: boolean;
15
+ handleSignals?: boolean;
16
+ /** Nyalakan $eval / $jsEval / bot.evalCommand (hanya untuk ID di `owners`). Bawaan: false */
17
+ eval?: boolean;
18
+ database?: { path?: string; memory?: boolean; saveDelay?: number } | Database;
19
+ messages?: { cooldown?: string; error?: string };
20
+ status?: { text: string; type?: 'Playing' | 'Streaming' | 'Listening' | 'Watching' | 'Competing'; status?: 'online' | 'idle' | 'dnd' | 'invisible' };
21
+ onError?: (error: Error, ctx: Context) => unknown;
22
+ client?: Client;
23
+ discord?: unknown;
24
+ }
25
+
26
+ export interface CommandDef { name: string; aliases?: string[]; code: string }
27
+ export interface SlashOption {
28
+ name: string;
29
+ description: string;
30
+ type?: 'string' | 'integer' | 'boolean' | 'user' | 'channel' | 'role' | 'mentionable' | 'number' | 'attachment';
31
+ required?: boolean;
32
+ choices?: Array<{ name: string; value: string | number }>;
33
+ minValue?: number;
34
+ maxValue?: number;
35
+ minLength?: number;
36
+ maxLength?: number;
37
+ /** Pilihan dinamis; daftarkan handler dengan bot.autocomplete(). Tidak bisa bersama `choices`. */
38
+ autocomplete?: boolean;
39
+ }
40
+ export interface AutocompleteDef { command: string; option?: string; code: string }
41
+ export interface ContextMenuDef { name: string; menu: 'user' | 'message'; code: string }
42
+ export interface SlashDef { name: string; description: string; options?: SlashOption[]; code: string }
43
+ export interface ComponentDef { customId: string; code: string }
44
+ export type EventType = 'ready' | 'memberJoin' | 'memberLeave' | 'messageDelete' | 'messageUpdate' | 'reactionAdd' | 'reactionRemove' | 'guildJoin' | 'guildLeave' | 'message'
45
+ | 'memberBan' | 'memberUnban' | 'channelCreate' | 'channelDelete' | 'roleCreate' | 'roleDelete' | 'threadCreate' | 'voiceJoin' | 'voiceLeave';
46
+ export interface EventDef { type: EventType; channel?: string; code: string }
47
+ export interface CustomFunction {
48
+ name: string;
49
+ params?: number;
50
+ min?: number;
51
+ max?: number;
52
+ brackets?: 'none' | 'optional' | 'required';
53
+ override?: boolean;
54
+ signature?: string;
55
+ description?: string;
56
+ run: (ctx: Context, args: string[]) => unknown | Promise<unknown>;
57
+ }
58
+
59
+ export class Context {
60
+ bot: Bot;
61
+ client: Client;
62
+ kind: 'message' | 'slash' | 'component' | 'event';
63
+ guild: any;
64
+ channel: any;
65
+ member: any;
66
+ user: any;
67
+ message: any;
68
+ interaction: any;
69
+ args: string[];
70
+ rawArgs: string;
71
+ }
72
+
73
+ export class Database {
74
+ constructor(options?: { path?: string; memory?: boolean; saveDelay?: number });
75
+ get(key: string): unknown;
76
+ set(key: string, value: unknown): void;
77
+ has(key: string): boolean;
78
+ delete(key: string): boolean;
79
+ keys(prefix?: string): string[];
80
+ flush(): void;
81
+ }
82
+
83
+ export class Bot {
84
+ constructor(options?: BotOptions);
85
+ client: Client | null;
86
+ db: Database;
87
+ command(def: CommandDef): this;
88
+ slashCommand(def: SlashDef): this;
89
+ button(def: ComponentDef): this;
90
+ select(def: ComponentDef): this;
91
+ modal(def: ComponentDef): this;
92
+ autocomplete(def: AutocompleteDef): this;
93
+ contextMenu(def: ContextMenuDef): this;
94
+ /** Pasang command eval siap pakai (butuh `eval: true` dan `owners`). */
95
+ evalCommand(def?: { name?: string; aliases?: string[] }): this;
96
+ event(def: EventDef): this;
97
+ onMemberBan(code: string | Omit<EventDef, 'type'>): this;
98
+ onMemberUnban(code: string | Omit<EventDef, 'type'>): this;
99
+ onChannelCreate(code: string | Omit<EventDef, 'type'>): this;
100
+ onChannelDelete(code: string | Omit<EventDef, 'type'>): this;
101
+ onRoleCreate(code: string | Omit<EventDef, 'type'>): this;
102
+ onRoleDelete(code: string | Omit<EventDef, 'type'>): this;
103
+ onThreadCreate(code: string | Omit<EventDef, 'type'>): this;
104
+ onVoiceJoin(code: string | Omit<EventDef, 'type'>): this;
105
+ onVoiceLeave(code: string | Omit<EventDef, 'type'>): this;
106
+ onReady(code: string | Omit<EventDef, 'type'>): this;
107
+ onMemberJoin(code: string | Omit<EventDef, 'type'>): this;
108
+ onMemberLeave(code: string | Omit<EventDef, 'type'>): this;
109
+ onMessageDelete(code: string | Omit<EventDef, 'type'>): this;
110
+ onMessageUpdate(code: string | Omit<EventDef, 'type'>): this;
111
+ onReactionAdd(code: string | Omit<EventDef, 'type'>): this;
112
+ onReactionRemove(code: string | Omit<EventDef, 'type'>): this;
113
+ onGuildJoin(code: string | Omit<EventDef, 'type'>): this;
114
+ onGuildLeave(code: string | Omit<EventDef, 'type'>): this;
115
+ onMessage(code: string | Omit<EventDef, 'type'>): this;
116
+ variables(vars: Record<string, string | number | boolean>): this;
117
+ addFunction(fn: CustomFunction): this;
118
+ loadCommands(dir: string): this;
119
+ validate(): true;
120
+ getVar(scope: 'user' | 'server' | 'channel' | 'global', name: string, id?: string | null): string;
121
+ setVar(scope: 'user' | 'server' | 'channel' | 'global', name: string, value: unknown, id?: string | null): void;
122
+ resetVar(scope: 'user' | 'server' | 'channel' | 'global', name: string, id?: string | null): void;
123
+ connect(token?: string): Promise<this>;
124
+ destroy(): Promise<void>;
125
+ }
126
+
127
+ export class BotError extends Error {}
128
+ export class ParseError extends BotError { line?: number; col?: number }
129
+ export class ValidationError extends BotError { problems: string[] }
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@tryty/easydc-js",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Bot Discord super mudah di atas discord.js: tulis perintah dengan sintaks $fungsi[arg] ala aoi.js.",
5
+ "main": "src/index.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "src",
9
+ "examples",
10
+ "index.d.ts",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "test": "node --test",
16
+ "docs": "node scripts/gen-docs.js"
17
+ },
18
+ "keywords": [
19
+ "discord",
20
+ "discord.js",
21
+ "bot",
22
+ "aoi.js",
23
+ "easy",
24
+ "wrapper"
25
+ ],
26
+ "author": "",
27
+ "license": "MIT",
28
+ "engines": {
29
+ "node": ">=18.17.0"
30
+ },
31
+ "dependencies": {
32
+ "discord.js": "^14.16.0"
33
+ }
34
+ }