mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Animal Crossing speak, morse encode/decode
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const path = require('path');
|
||||
const { wait } = require('../../util/Util');
|
||||
|
||||
module.exports = class AnimalCrossingSpeakCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'animal-crossing-speak',
|
||||
aliases: ['animal-crossing-speech', 'ac-speak', 'ac-speech'],
|
||||
group: 'text-edit',
|
||||
memberName: 'animal-crossing-speak',
|
||||
description: 'Converts text to Animal Crossing Speak.',
|
||||
guildOnly: true,
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 10
|
||||
},
|
||||
args: [
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What text do you want to say?',
|
||||
type: 'string',
|
||||
parse: text => text.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { text }) {
|
||||
const channel = msg.member.voiceChannel;
|
||||
if (!channel) return msg.say('Please enter a voice channel first.');
|
||||
if (!channel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) {
|
||||
return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.');
|
||||
}
|
||||
if (!channel.joinable) return msg.say('Your voice channel is not joinable.');
|
||||
if (this.client.voiceConnections.has(channel.guild.id)) return msg.say('I am already playing a sound.');
|
||||
try {
|
||||
const connection = await channel.join();
|
||||
for (const letter of text.split('')) {
|
||||
if (letter === ' ') await wait(500);
|
||||
else if (!/[a-z0-9]/.test(letter)) await this.playLetter(connection, 'unknown');
|
||||
else await this.playLetter(connection, letter);
|
||||
}
|
||||
channel.leave();
|
||||
return null;
|
||||
} catch (err) {
|
||||
channel.leave();
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
playLetter(connection, letter) {
|
||||
const letterPath = path.join(__dirname, '..', '..', 'assets', 'sounds', 'animal-crossing-speak', `${letter}.wav`);
|
||||
return new Promise((res, rej) => {
|
||||
const dispatcher = connection.playFile(letterPath);
|
||||
dispatcher.once('end', reason => res(reason));
|
||||
dispatcher.once('error', err => rej(err));
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { pad } = require('../../util/Util');
|
||||
const { list, pad } = require('../../util/Util');
|
||||
const modes = ['encode', 'decode'];
|
||||
|
||||
module.exports = class BinaryCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -9,6 +10,17 @@ module.exports = class BinaryCommand extends Command {
|
||||
memberName: 'binary',
|
||||
description: 'Converts text to binary.',
|
||||
args: [
|
||||
{
|
||||
key: 'mode',
|
||||
prompt: `Would you like to ${list(modes, 'or')}?`,
|
||||
type: 'string',
|
||||
format: `<${modes.join('|')}>`,
|
||||
validate: mode => {
|
||||
if (modes.includes(mode.toLowerCase())) return true;
|
||||
return `Invalid mode, please enter either ${list(modes, 'or')}.`;
|
||||
},
|
||||
parse: mode => mode.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What text would you like to convert to binary?',
|
||||
@@ -22,14 +34,19 @@ module.exports = class BinaryCommand extends Command {
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { text }) {
|
||||
return msg.say(this.binary(text));
|
||||
run(msg, { mode, text }) { // eslint-disable-line consistent-return
|
||||
if (mode === 'encode') return msg.say(this.binary(text));
|
||||
else if (mode === 'decode') return msg.say(this.unbinary(text));
|
||||
}
|
||||
|
||||
binary(text) {
|
||||
return text.split('').map(str => {
|
||||
const converted = str.charCodeAt(0).toString(2);
|
||||
return pad(converted, '00000000');
|
||||
}).join('');
|
||||
}).join(' ');
|
||||
}
|
||||
|
||||
unbinary(text) {
|
||||
return text.split(' ').map(str => String.fromCharCode(parseInt(str, 2))).join('');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,10 +22,7 @@ module.exports = class QRCodeCommand extends Command {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get('https://api.qrserver.com/v1/create-qr-code/')
|
||||
.query({
|
||||
data: text,
|
||||
size: '500x500'
|
||||
});
|
||||
.query({ data: text });
|
||||
return msg.say({ files: [{ attachment: body, name: 'qr-code.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "59.0.0",
|
||||
"version": "60.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user