Skip to content

Commit

Permalink
Releasing v1.0.0 (#516)
Browse files Browse the repository at this point in the history
* chore: added yarn dev (for alias)

* style: code style unified

* chore: update import path

* types: added return type and removed any

* chore: updated types and made changes on owner method

* types: fixed inspect type

* deps: changed dokdo version

* cd: removed reviewdog action

* types: fixed ts compile error (temporary)

* chore: removed djsDocs

* types: fixed type issues

* chore: removed djsDocs

* chore: removed djsDocs

* chore: improved code style

* deps: fixed dependecy issue

* docs: changed example
  • Loading branch information
wonderlandpark authored Jul 8, 2023
1 parent 9a206b8 commit cb075cd
Show file tree
Hide file tree
Showing 25 changed files with 1,091 additions and 780 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/reviewdog.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] })

const Dokdo = require('dokdo')

const DokdoHandler = new Dokdo(client, { aliases: ['dokdo', 'dok'], prefix: '!' }) // Using Bot Application ownerID as default for owner option.
const DokdoHandler = new Dokdo.Client(client, { aliases: ['dokdo', 'dok'], prefix: '!' }) // Using Bot Application ownerID as default for owner option.

client.on('messageCreate', async message => {
if (message.content === 'ping') return message.channel.send('Pong') // handle commands first
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "dokdo",
"version": "0.6.2",
"version": "1.0.0",
"description": "Dokdo. Easy Discord bot debuging tool.",
"scripts": {
"build": "tsup",
"dev": "yarn test:bot",
"lint": "eslint --ext js,jsx,ts,tsx src",
"lint:fix": "eslint --ext js,jsx,ts,tsx src --fix",
"test": "yarn build && mocha --exit",
Expand All @@ -12,10 +13,10 @@
"update": "yarn upgrade-interactive"
},
"main": "./dist/index.js",
"module": "./esm/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"exports": {
"import": "./esm/index.js",
"import": "./dist/esm/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
Expand Down
7 changes: 5 additions & 2 deletions src/commands/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { ButtonBuilder, ButtonStyle, Message } from 'discord.js'
import { ProcessManager, HLJS } from '../utils'
import type { Client } from '../'

export async function cat (message: Message, parent: Client) {
if (!message.data.args) return message.reply('Missing Arguments.')
export async function cat (message: Message, parent: Client): Promise<void> {
if (!message.data.args) {
message.reply('Missing Arguments.')
return
}
const filename = message.data.args
let msg
fs.readFile(filename, async (err, data) => {
Expand Down
25 changes: 14 additions & 11 deletions src/commands/curl.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import fetch from 'node-fetch'
import Discord, { Message } from 'discord.js'
import { ButtonBuilder, ButtonStyle, Message } from 'discord.js'
import { ProcessManager, HLJS } from '../utils'
import type { Client } from '../'

export async function curl (message: Message, parent: Client) {
if (!message.data.args) return message.reply('Missing Arguments.')
export async function curl (message: Message, parent: Client): Promise<void> {
if (!message.data.args) {
message.reply('Missing Arguments.')
return
}

let type
const res = await fetch(message.data.args.split(' ')[0]!)
.then(async (r) => {
const res = await fetch(message.data.args.split(' ')[0] as string)
.then(async r => {
const text = await r.text()
try {
type = 'json'
Expand All @@ -30,24 +33,24 @@ export async function curl (message: Message, parent: Client) {
await msg.init()
await msg.addAction([
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Danger)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setCustomId('dokdo$prev')
.setLabel('Prev'),
action: ({ manager }) => manager.previousPage(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Secondary)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setCustomId('dokdo$stop')
.setLabel('Stop'),
action: ({ manager }) => manager.destroy(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Success)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Success)
.setCustomId('dokdo$next')
.setLabel('Next'),
action: ({ manager }) => manager.nextPage(),
Expand Down
7 changes: 0 additions & 7 deletions src/commands/docs.ts

This file was deleted.

41 changes: 20 additions & 21 deletions src/commands/exec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import child from 'child_process'
import Discord, { Message } from 'discord.js'
import { ButtonBuilder, ButtonStyle, Message } from 'discord.js'
import type { Client } from '../'
import { ProcessManager, codeBlock } from '../utils'

export async function exec (message: Message, parent: Client) {
if (!message.data.args) return message.reply('Missing Arguments.')
export async function exec (message: Message, parent: Client): Promise<void> {
if (!message.data.args) {
message.reply('Missing Arguments.')
return
}

const shell =
process.env.SHELL || (process.platform === 'win32' ? 'powershell' : null)
console.log(shell)
if (!shell) {
return message.reply(
message.reply(
'Sorry, we are not able to find your default shell.\nPlease set `process.env.SHELL`.'
)
return
}

const msg = new ProcessManager(message, `$ ${message.data.args}\n`, parent, {
Expand All @@ -28,35 +31,33 @@ export async function exec (message: Message, parent: Client) {
kill(res, 'SIGTERM')
message.reply('Shell timeout occured.')
}, 180000)
console.log(res.pid)

await msg.addAction(
[
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Danger)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setCustomId('dokdo$prev')
.setLabel('Prev'),
action: ({ manager }) => manager.previousPage(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Secondary)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setCustomId('dokdo$stop')
.setLabel('Stop'),
action: async ({ res, manager }) => {
res.stdin.pause()
const gg = await kill(res)
console.log(gg)
kill(res)
msg.add('^C')
manager.destroy()
},
requirePage: true
requirePage: false
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Success)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Success)
.setCustomId('dokdo$next')
.setLabel('Next'),
action: ({ manager }) => manager.nextPage(),
Expand All @@ -67,16 +68,14 @@ export async function exec (message: Message, parent: Client) {
)

res.stdout.on('data', (data) => {
console.log(data.toString())
msg.add('\n' + data.toString())
msg.add(data.toString())
})

res.stderr.on('data', (data) => {
msg.add(`\n[stderr] ${data.toString()}`)
msg.add(`[stderr] ${data.toString()}`)
})

res.on('error', (err) => {
console.log(err)
return message.reply(
`Error occurred while spawning process\n${codeBlock.construct(
err.toString(),
Expand All @@ -85,12 +84,12 @@ export async function exec (message: Message, parent: Client) {
)
})
res.on('close', (code) => {
console.log(clearTimeout(timeout))
clearTimeout(timeout)
msg.add(`\n[status] process exited with code ${code}`)
})
}

function kill (res: any, signal?: NodeJS.Signals) {
function kill (res: child.ChildProcessWithoutNullStreams, signal?: NodeJS.Signals) {
if (process.platform === 'win32') {
return child.exec(
`powershell -File "..\\utils\\KillChildrenProcess.ps1" ${res.pid}`,
Expand Down
1 change: 0 additions & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export * from './shard'
export * from './jsi'
export * from './curl'
export * from './cat'
export * from './docs'
37 changes: 21 additions & 16 deletions src/commands/js.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Discord, { Message } from 'discord.js'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Discord, { Embed, EmbedBuilder, Collection, Attachment, ButtonBuilder, ButtonStyle, Message } from 'discord.js'
import type { Client, Context } from '../'
import { ProcessManager, inspect, isInstance, isGenerator } from '../utils'

export async function js (message: Context, parent: Client) {
export async function js (message: Context, parent: Client): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { client } = parent // for eval
const isMessage = message instanceof Message
if (isMessage && !message.data.args) { return message.reply('Missing Arguments.') }
if (isMessage && !message.data.args) {
message.reply('Missing Arguments.')
return
}

const res = new Promise((resolve) =>
resolve(
Expand All @@ -20,23 +24,24 @@ export async function js (message: Context, parent: Client) {
)
let typeOf
const result = await res
.then(async (output) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then(async (output: any) => {
typeOf = typeof output

async function prettify (target: any) {
async function prettify (target: unknown): Promise<void> {
if (
target instanceof Discord.Embed ||
target instanceof Discord.EmbedBuilder
) { await message.reply({ embeds: [target] }) } else if (isInstance(target, Discord.Attachment)) {
target instanceof Embed ||
target instanceof EmbedBuilder
) { await message.reply({ embeds: [target] }) } else if (isInstance(target, Attachment)) {
await message.reply({
files:
target instanceof Discord.Collection ? target.toJSON() : [target]
target instanceof Collection ? target.toJSON() : [target]
})
}
}

if (isGenerator(output)) {
for (const value of output as any) {
for (const value of output) {
prettify(value)

if (typeof value === 'function') { await message.reply(value.toString()) } else if (typeof value === 'string') await message.reply(value)
Expand Down Expand Up @@ -70,24 +75,24 @@ export async function js (message: Context, parent: Client) {
await msg.init()
await msg.addAction([
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Danger)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setCustomId('dokdo$prev')
.setLabel('Prev'),
action: ({ manager }) => manager.previousPage(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Secondary)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setCustomId('dokdo$stop')
.setLabel('Stop'),
action: ({ manager }) => manager.destroy(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Success)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Success)
.setCustomId('dokdo$next')
.setLabel('Next'),
action: ({ manager }) => manager.nextPage(),
Expand Down
23 changes: 13 additions & 10 deletions src/commands/jsi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Discord, { Message } from 'discord.js'
import { Collection, ButtonBuilder, ButtonStyle, Message } from 'discord.js'
import type { Client } from '../'
import { ProcessManager, count, inspect, table, typeFind } from '../utils'

export async function jsi (message: Message, parent: Client) {
export async function jsi (message: Message, parent: Client): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { client } = parent
if (!message.data.args) return message.reply('Missing Arguments.')
if (!message.data.args) {
message.reply('Missing Arguments.')
return
}

// eslint-disable-next-line no-eval
const res = new Promise((resolve) => resolve(eval(message.data.args ?? '')))
Expand All @@ -27,7 +30,7 @@ export async function jsi (message: Message, parent: Client) {
Type: `${typeof output}(${typeofTheRes})`,
Name: constructorName || null,
Length: typeof output === 'string' && output.length,
Size: output instanceof Discord.Collection ? output.size : null,
Size: output instanceof Collection ? output.size : null,
'Content Types': arrCount
? arrCount.map((el) => `${el.name} (${el.ratio}%)`).join(', ')
: null
Expand All @@ -43,24 +46,24 @@ export async function jsi (message: Message, parent: Client) {
await msg.init()
await msg.addAction([
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Danger)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setCustomId('dokdo$prev')
.setLabel('Prev'),
action: ({ manager }) => manager.previousPage(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Secondary)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setCustomId('dokdo$stop')
.setLabel('Stop'),
action: ({ manager }) => manager.destroy(),
requirePage: true
},
{
button: new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Success)
button: new ButtonBuilder()
.setStyle(ButtonStyle.Success)
.setCustomId('dokdo$next')
.setLabel('Next'),
action: ({ manager }) => manager.nextPage(),
Expand Down
Loading

0 comments on commit cb075cd

Please sign in to comment.