Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.37.0 #73

Merged
merged 7 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "borobot",
"version": "1.36.0",
"version": "1.37.0",
"description": "A simple Discord Bot build with Discord.js",
"displayName": "Borobot",
"bugs": {
Expand Down Expand Up @@ -46,6 +46,7 @@
"canvas": "^2.10.2",
"change-case": "^4.1.2",
"color-convert": "^2.0.1",
"convert": "^4.9.0",
"ctk-anime-scraper": "^3.5.0",
"discord-api-types": "^0.37.23",
"discord-image-generation": "^1.4.15",
Expand All @@ -70,13 +71,13 @@
"qrcode": "^1.5.1",
"roman-numerals-convert": "^1.0.5",
"string-progressbar": "^1.0.4",
"tesseract.js": "^4.0.1",
"tesseract.js": "^4.0.2",
"weather-js": "^2.0.0",
"yt-search": "^2.10.3",
"ytdl-core": "^4.11.2"
},
"devDependencies": {
"eslint": "^8.29.0",
"eslint": "^8.30.0",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"nodemon": "^2.0.20",
Expand All @@ -86,4 +87,4 @@
"*.ts": "eslint --cache --fix",
"*.{ts,css,md}": "prettier --write"
}
}
}
92 changes: 92 additions & 0 deletions src/commands/misc/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { convert } = require('convert');
const { bold, codeBlock, SlashCommandBuilder } = require('discord.js');

const { units } = require('../../constants');
const { generateEmbed, generatePagination } = require('../../utils');

module.exports = {
data: new SlashCommandBuilder()
.setName('convert')
.setDescription('🚀 Converter command.')
.addSubcommand((subcommand) =>
subcommand.setName('list').setDescription('📄 View available SI units.'),
)
.addSubcommand((subcommand) =>
subcommand
.setName('run')
.setDescription('🚀 convert an amount from one unit to another.')
.addIntegerOption((option) =>
option
.setName('amount')
.setDescription('🔢 The amount of the unit to be converted.')
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('from')
.setDescription('♾️ The unit to convert from.')
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('to')
.setDescription('♾️ The unit to convert to.')
.setRequired(true),
),
),
type: 'Chat Input',

/**
*
* @param {import('discord.js').ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
const { options } = interaction;
const embed = generateEmbed({ interaction });

await interaction.deferReply();

return {
list: async () => {
const responses = units
.sort((a, b) => a.localeCompare(b))
.map((unit, i) => `${bold(`${i + 1}`)} - ${unit}`);

await generatePagination({ interaction, limit: 10 })
.setAuthor({
name: `📄 SI Unit Lists (${units.length.toLocaleString()})`,
})
.setDescriptions(responses)
.render();
},
run: async () => {
const amount = options.getInteger('amount', true);
const from = options.getString('from', true);
const to = options.getString('to', true);
const fromUnit = units.find(
(unit) => unit.toLowerCase() === from.toLowerCase(),
);
const toUnit = units.find(
(unit) => unit.toLowerCase() === to.toLowerCase(),
);

if (!fromUnit || !toUnit) {
throw 'Please provide a valid unit.';
}

/** @type {Number} */
const result = convert(amount, fromUnit).to(toUnit);

embed
.setAuthor({
name: '🚀 Conversion Result',
})
.setDescription(
codeBlock(`${amount} ${fromUnit} = ${result} ${toUnit}`),
);

await interaction.editReply({ embeds: [embed] });
},
}[options.getSubcommand()]();
},
};
2 changes: 1 addition & 1 deletion src/commands/mod/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
const wait = require('node:timers/promises').setTimeout;

const { banChoices, banTempChoices } = require('../../constants');
const { generatePagination, generateEmbed } = require('../../utils');
const { generateEmbed, generatePagination } = require('../../utils');

module.exports = {
data: new SlashCommandBuilder()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mod/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
} = require('discord.js');

const { timeoutChoices } = require('../../constants');
const { generatePagination, generateEmbed } = require('../../utils');
const { generateEmbed, generatePagination } = require('../../utils');

module.exports = {
data: new SlashCommandBuilder()
Expand Down
86 changes: 79 additions & 7 deletions src/commands/systems/ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ module.exports = {
data: new SlashCommandBuilder()
.setName('ai')
.setDescription('🤖 AI Command.')
.addSubcommand((subcommand) =>
subcommand
.setName('grammar')
.setDescription('🔤 Run a grammar correction with OpenAI.')
.addStringOption((option) =>
option
.setName('prompt')
.setDescription('❓ The command to generate.')
.setRequired(true),
),
)
.addSubcommand((subcommand) =>
subcommand
.setName('image')
.setDescription('🖼️ Generate Image with OpenAI.')
.addStringOption((option) =>
option
.setName('prompt')
.setDescription('❓ The command to generate.')
.setRequired(true),
),
)
.addSubcommand((subcommand) =>
subcommand
.setName('text')
Expand All @@ -18,6 +40,7 @@ module.exports = {
.setRequired(true),
),
),

type: 'Chat Input',

/**
Expand All @@ -34,23 +57,72 @@ module.exports = {
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const attachment = new AttachmentBuilder(
'./src/assets/images/openai-logo.png',
{ name: 'openai-logo.png' },
);
const prompt = options.getString('prompt', true);

return {
text: async () => {
const prompt = options.getString('prompt', true);
grammar: async () => {
const {
data: {
choices: [{ text }],
},
} = await openai.createCompletion({
model: 'text-davinci-003',
prompt,
temperature: 0,
max_tokens: 60,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

embed
.setAuthor({
name: 'AI Search Result',
iconURL: 'attachment://openai-logo.png',
})
.setFields([
{ name: '🔠 Prompt', value: prompt },
{ name: '🔠 Completion', value: text },
]);

await interaction.editReply({ embeds: [embed], files: [attachment] });
},
image: async () => {
const {
data: { data },
} = await openai.createImage({ prompt });

const attachment = new AttachmentBuilder(
'./src/assets/images/openai-logo.png',
{ name: 'openai-logo.png' },
);
if (!data[0].url) {
throw 'No image can be found.';
}

embed
.setAuthor({
name: 'AI Search Result',
iconURL: 'attachment://openai-logo.png',
})
.setImage(data[0].url)
.setFields([{ name: '🔠 Prompt', value: prompt }]);

await interaction.editReply({ embeds: [embed], files: [attachment] });
},
text: async () => {
const {
data: {
choices: [{ text }],
},
} = await openai.createCompletion({
model: 'text-davinci-002',
model: 'text-davinci-003',
prompt,
temperature: 0,
max_tokens: 60,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

embed
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tools/inrole.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { bold, SlashCommandBuilder } = require('discord.js');

const { generatePagination, generateEmbed } = require('../../utils');
const { generateEmbed, generatePagination } = require('../../utils');

module.exports = {
data: new SlashCommandBuilder()
Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {
waifuChoices,
youtubeDownloadTypeChoices,
} = require('./slashCommandOptionChoices');
const { units } = require('./units');
const { vtuberAffiliation } = require('./vtuberData');

module.exports = {
Expand Down Expand Up @@ -67,6 +68,7 @@ module.exports = {
tiktokDownloadTypeChoices,
timeoutChoices,
twitterDownloadTypeChoices,
units,
vtuberAffiliation,
vtuberVideoSortingChoices: vtuberVideoSorting,
vtuberStreamSortingChoices: [...vtuberVideoSorting, ...vtuberStreamSorting],
Expand Down
Loading