This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from takejohn/dev/refactoring
自動整形ツール・リファクタリング
- Loading branch information
Showing
61 changed files
with
12,149 additions
and
11,162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.md | ||
*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"useTabs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
{ | ||
// IntelliSense を使用して利用可能な属性を学べます。 | ||
// 既存の属性の説明をホバーして表示します。 | ||
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "プログラムの起動", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}\\discordbot.js" | ||
} | ||
] | ||
// IntelliSense を使用して利用可能な属性を学べます。 | ||
// 既存の属性の説明をホバーして表示します。 | ||
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "プログラムの起動", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}\\discordbot.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,66 @@ | ||
const { SlashCommandBuilder, CommandInteraction } = require('discord.js'); | ||
const { LANG, strFormat } = require('../util/languages'); | ||
const { CheckHostRequest, CHECK_PING, CheckPingOk, isValidHostname } = require('../util/check-host'); | ||
const { formatTable } = require('../util/strings'); | ||
const { SlashCommandBuilder } = require("discord.js"); | ||
const { LANG, strFormat } = require("../util/languages"); | ||
const { | ||
CheckHostRequest, | ||
CHECK_PING, | ||
CheckPingOk, | ||
isValidHostname, | ||
} = require("../util/check-host"); | ||
const { formatTable } = require("../util/strings"); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName(LANG.commands.checkping.name) | ||
.setDescription(LANG.commands.checkping.description) | ||
.addStringOption(option => ( | ||
option | ||
.setName(LANG.commands.checkping.options.ip.name) | ||
.setDescription(LANG.common.optionDescription.ipAddress) | ||
.setRequired(true) | ||
)), | ||
execute: async function (/** @type {CommandInteraction} */ interaction) { | ||
let url = interaction.options.getString(LANG.commands.checkping.options.ip.name); | ||
if (!isValidHostname(url)) { | ||
// IPアドレスが間違っています。(IPv4、またはドメインのみ対応しています。 | ||
return await interaction.reply(LANG.commands.checkping.invalidIpError); | ||
} | ||
const request = await CheckHostRequest.get(CHECK_PING, url, 40); | ||
const msg = await interaction.reply(LANG.common.message.checking); | ||
const resultMap = await request.checkResult(1.0, 7); | ||
const table = [...resultMap.entries()].map(([node, result]) => { | ||
const nodeName = node.name.replace(".node.check-host.net", ""); | ||
const prefix = `[${nodeName}]`; | ||
console.log(strFormat(LANG.common.message.dataFor, [nodeName]), result); | ||
if (result instanceof CheckPingOk) { | ||
const values = result.values; | ||
const average = values.reduce((a, { ping: b }) => a + b, 0) / values.length; | ||
return [ | ||
prefix, values[3].reply + ',', values[3].ping, '/', values[2].reply + ',', values[2].ping, | ||
'| Ping:', `${Math.floor(average * 1000)} ms` | ||
]; | ||
} | ||
return [prefix, result.state]; | ||
}); | ||
const str = formatTable(table, { | ||
align: ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'right'] | ||
}); | ||
msg.edit({ | ||
content: LANG.common.message.result, | ||
files: [{ | ||
attachment: Buffer.from(str), | ||
name: "result.txt" | ||
}] | ||
}) | ||
} | ||
}; | ||
data: new SlashCommandBuilder() | ||
.setName(LANG.commands.checkping.name) | ||
.setDescription(LANG.commands.checkping.description) | ||
.addStringOption((option) => | ||
option | ||
.setName(LANG.commands.checkping.options.ip.name) | ||
.setDescription(LANG.common.optionDescription.ipAddress) | ||
.setRequired(true), | ||
), | ||
execute: async function (/** @type {CommandInteraction} */ interaction) { | ||
const url = interaction.options.getString( | ||
LANG.commands.checkping.options.ip.name, | ||
); | ||
if (!isValidHostname(url)) { | ||
// IPアドレスが間違っています。(IPv4、またはドメインのみ対応しています。 | ||
return await interaction.reply(LANG.commands.checkping.invalidIpError); | ||
} | ||
const request = await CheckHostRequest.get(CHECK_PING, url, 40); | ||
const msg = await interaction.reply(LANG.common.message.checking); | ||
const resultMap = await request.checkResult(1.0, 7); | ||
const table = [...resultMap.entries()].map(([node, result]) => { | ||
const nodeName = node.name.replace(".node.check-host.net", ""); | ||
const prefix = `[${nodeName}]`; | ||
console.log(strFormat(LANG.common.message.dataFor, [nodeName]), result); | ||
if (result instanceof CheckPingOk) { | ||
const values = result.values; | ||
const average = | ||
values.reduce((a, { ping: b }) => a + b, 0) / values.length; | ||
return [ | ||
prefix, | ||
values[3].reply + ",", | ||
values[3].ping, | ||
"/", | ||
values[2].reply + ",", | ||
values[2].ping, | ||
"| Ping:", | ||
`${Math.floor(average * 1000)} ms`, | ||
]; | ||
} | ||
return [prefix, result.state]; | ||
}); | ||
const str = formatTable(table, { | ||
align: ["left", "left", "left", "left", "left", "left", "left", "right"], | ||
}); | ||
msg.edit({ | ||
content: LANG.common.message.result, | ||
files: [ | ||
{ | ||
attachment: Buffer.from(str), | ||
name: "result.txt", | ||
}, | ||
], | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,62 @@ | ||
const { SlashCommandBuilder } = require('discord.js'); | ||
const { LANG, strFormat } = require('../util/languages'); | ||
const { CheckHostRequest, CHECK_TCP, CheckTcpOk, CheckTcpError, isValidHostname } = require('../util/check-host'); | ||
const { formatTable } = require('../util/strings'); | ||
const { SlashCommandBuilder } = require("discord.js"); | ||
const { LANG, strFormat } = require("../util/languages"); | ||
const { | ||
CheckHostRequest, | ||
CHECK_TCP, | ||
CheckTcpOk, | ||
CheckTcpError, | ||
isValidHostname, | ||
} = require("../util/check-host"); | ||
const { formatTable } = require("../util/strings"); | ||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName(LANG.commands.checktcp.name) | ||
.setDescription(LANG.commands.checktcp.description) | ||
.addStringOption(option => ( | ||
option | ||
.setName(LANG.commands.checktcp.options.ip.name) | ||
.setDescription(LANG.common.optionDescription.ipAddress) | ||
.setRequired(true) | ||
)), | ||
execute: async function (interaction) { | ||
const url = interaction.options.getString(LANG.commands.checktcp.options.ip.name); | ||
if (!isValidHostname(url)) { | ||
return await interaction.reply(LANG.commands.checktcp.invalidUrlError); | ||
} | ||
const request = await CheckHostRequest.get(CHECK_TCP, url, 40); | ||
const msg = await interaction.reply(LANG.common.message.checking); | ||
const resultMap = await request.checkResult(1.0, 7); | ||
const table = [...resultMap.entries()].map(([node, result]) => { | ||
const nodeName = node.name.replace(".node.check-host.net", ""); | ||
const prefix = `[${nodeName}]`; | ||
console.log(strFormat(LANG.common.message.dataFor, [nodeName]), result); | ||
if (result instanceof CheckTcpOk) { | ||
return [prefix, 'OK,', result.time, '| Ping: ', `${Math.floor(result.time * 1000)} ms`]; | ||
} | ||
if (result instanceof CheckTcpError) { | ||
return [prefix, 'ERROR', result.description]; | ||
} | ||
return [prefix, result.state]; | ||
}); | ||
const str = formatTable(table, { | ||
align: ['left', 'left', 'left', 'left', 'right'] | ||
}); | ||
msg.edit({ | ||
content: LANG.common.message.result, | ||
files: [{ | ||
attachment: Buffer.from(str), | ||
name: "result.txt" | ||
}] | ||
}); | ||
} | ||
}; | ||
data: new SlashCommandBuilder() | ||
.setName(LANG.commands.checktcp.name) | ||
.setDescription(LANG.commands.checktcp.description) | ||
.addStringOption((option) => | ||
option | ||
.setName(LANG.commands.checktcp.options.ip.name) | ||
.setDescription(LANG.common.optionDescription.ipAddress) | ||
.setRequired(true), | ||
), | ||
execute: async function (interaction) { | ||
const url = interaction.options.getString( | ||
LANG.commands.checktcp.options.ip.name, | ||
); | ||
if (!isValidHostname(url)) { | ||
return await interaction.reply(LANG.commands.checktcp.invalidUrlError); | ||
} | ||
const request = await CheckHostRequest.get(CHECK_TCP, url, 40); | ||
const msg = await interaction.reply(LANG.common.message.checking); | ||
const resultMap = await request.checkResult(1.0, 7); | ||
const table = [...resultMap.entries()].map(([node, result]) => { | ||
const nodeName = node.name.replace(".node.check-host.net", ""); | ||
const prefix = `[${nodeName}]`; | ||
console.log(strFormat(LANG.common.message.dataFor, [nodeName]), result); | ||
if (result instanceof CheckTcpOk) { | ||
return [ | ||
prefix, | ||
"OK,", | ||
result.time, | ||
"| Ping: ", | ||
`${Math.floor(result.time * 1000)} ms`, | ||
]; | ||
} | ||
if (result instanceof CheckTcpError) { | ||
return [prefix, "ERROR", result.description]; | ||
} | ||
return [prefix, result.state]; | ||
}); | ||
const str = formatTable(table, { | ||
align: ["left", "left", "left", "left", "right"], | ||
}); | ||
msg.edit({ | ||
content: LANG.common.message.result, | ||
files: [ | ||
{ | ||
attachment: Buffer.from(str), | ||
name: "result.txt", | ||
}, | ||
], | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.