Skip to content

Commit

Permalink
added piano
Browse files Browse the repository at this point in the history
Added basic functionality for /piano for Utility Bot
C5 Major only
  • Loading branch information
CCheukKa committed Mar 18, 2021
1 parent 17b5d03 commit 0b0cadd
Show file tree
Hide file tree
Showing 1,816 changed files with 363,098 additions and 23 deletions.
Binary file added Discord Bots/Testing/appdata/notes/A#.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/A.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/B.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/C#.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/C.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/D#.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/D.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/E.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/F#.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/F.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/G#.wav
Binary file not shown.
Binary file added Discord Bots/Testing/appdata/notes/G.wav
Binary file not shown.
93 changes: 74 additions & 19 deletions Discord Bots/Testing/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,93 @@
const Discord = require('discord.js');
const fs = require('fs');
const bot = new Discord.Client();

const token = 'no lol';
const token = fs.readFileSync('./appdata/token.txt', 'utf-8');
bot.login(token);

const prefix = '/';

let slots = [];
let progress = []; //1=started 2=finished 3=abandoned
var latest = 0;
const allow = [];
var channels = [];
var intervalId = 0;
var pianoMessage;
var pianoConnection;
var pianoChannel;

bot.on('ready', () => { console.log('Bot is online'); })
//bot.on('message', msg => {if(msg.content === "HELLO"){msg.reply('HELLO!')};})

bot.on('message', message => {



let args = message.content.substring(prefix.length).split(" ");
if (message.content.substring(0, 1) === prefix) {
if (allow.length > 0 && !allow.includes(args[0])) { console.log("Returned: " + args[0]); return; }


switch (args[0]) {
case 'cls':
message.channel.bulkDelete(99);
case 'piano':
if (!message.member.voice.channel) {
message.reply(`join a voice channel first!`);
return;
}
message.reply(`here's your piano:\nCareful, I may be loud!`).then(msg => {
pianoMessage = msg;
msg.react('🇦');
msg.react('🇧');
msg.react('🇨');
msg.react('🇩');
msg.react('🇪');
msg.react('🇫');
msg.react('🇬');
});
message.member.voice.channel.join().then(connection => {
pianoConnection = connection;
pianoChannel = message.member.voice.channel;
}).catch(console.error('Connection failed to attach'));
break;
case 'test':
message.reply(message.member.time);

case 'unpiano':
if (!pianoChannel) {
pianoChannel.leave();
}
pianoChannel = null;
pianoConnection = null;
pianoMessage = null;
message.reply('unpianoed');
break;

}
}
})
})

bot.on('messageReactionAdd', (reaction, user) => {
if (user.id == bot.user.id) { return; }
if (!pianoMessage) { return; }
if (reaction.message.id != pianoMessage.id) { return; }
var note;
switch (reaction.emoji.name) {
case '🇦':
note = 'A';
break;
case '🇧':
note = 'B';
break;
case '🇨':
note = 'C';
break;
case '🇩':
note = 'D';
break;
case '🇪':
note = 'E';
break;
case '🇫':
note = 'F';
break;
case '🇬':
note = 'G';
break;
default:
reaction.users.remove(user.id).catch(console.error('Failed to remove reaction'));
return;
}
reaction.users.remove(user.id).catch(console.error('Failed to remove reaction'));
console.log(`${user.username} played ${note}`);

//Play:
const dispatcher = pianoConnection.play(`./appdata/notes/${note}.wav`);
//
return;
});
19 changes: 19 additions & 0 deletions Discord Bots/Testing/node_modules/@derhuerst/http-basic/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions Discord Bots/Testing/node_modules/@derhuerst/http-basic/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b0cadd

Please sign in to comment.