mirror of
https://github.com/gizmo4487/O-Bot.git
synced 2025-05-30 20:22:31 -05:00
Added o!tetrio-rooms
Can now view the TETR.IO room list
This commit is contained in:
parent
cdd25ba2ab
commit
0608f74d7b
87
o-bot.js
87
o-bot.js
@ -1,4 +1,5 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
|
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
||||||
const Constants = require('discord.js/src/util/Constants.js');
|
const Constants = require('discord.js/src/util/Constants.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
Constants.DefaultOptions.ws.properties.$browser='Discord Android';
|
Constants.DefaultOptions.ws.properties.$browser='Discord Android';
|
||||||
@ -11,36 +12,42 @@ const bot = new Discord.Client({autoReconnect:true});
|
|||||||
|
|
||||||
// Display console message when logged in
|
// Display console message when logged in
|
||||||
bot.once('ready', () => {
|
bot.once('ready', () => {
|
||||||
console.log('Connected');
|
console.log('O-Bot is ready!');
|
||||||
bot.user.setActivity('Puyo Puyo\u2122Tetris\u00AE',{type: 'PLAYING'});
|
bot.user.setActivity('Puyo Puyo\u2122Tetris\u00AE 2',{type: 'PLAYING'});
|
||||||
|
|
||||||
|
// Uncomment to set status to "idle"
|
||||||
|
/*bot.user.setPresence({
|
||||||
|
status: 'idle'
|
||||||
|
});*/
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reconnecting
|
// Reconnecting
|
||||||
bot.on("reconnecting", () => {
|
bot.on("reconnecting", () => {
|
||||||
console.log("[" + getTime() + "] Reconnecting!");
|
console.log("Reconnecting!");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resume
|
// Resume
|
||||||
bot.on("resume", () => {
|
bot.on("resume", () => {
|
||||||
console.log("[" + getTime() + "] Connection restored!");
|
console.log("Connection restored!");
|
||||||
bot.user.setActivity('Puyo Puyo\u2122Tetris\u00AE',{type: 'PLAYING'});
|
bot.user.setActivity('Puyo Puyo\u2122Tetris\u00AE 2',{type: 'PLAYING'});
|
||||||
});
|
});
|
||||||
|
|
||||||
//bot.on('debug', console.log);
|
//bot.on('debug', console.log);
|
||||||
bot.on('message', message => {
|
bot.on('message', message => {
|
||||||
|
bot.user.setActivity('Puyo Puyo\u2122Tetris\u00AE 2',{type: 'PLAYING'});
|
||||||
// Prefix is 'o!'
|
// Prefix is 'o!'
|
||||||
if (message.content.substring(0, 2) == 'o!') {
|
if (message.content.substring(0, 2) == 'o!') {
|
||||||
var args = message.content.substring(2).split(' ');
|
var args = message.content.substring(2).split(' ');
|
||||||
var cmd = args[0];
|
var cmd = args[0];
|
||||||
|
|
||||||
args = args.splice(1);
|
args = args.splice(1);
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
|
|
||||||
// o!help
|
// o!help
|
||||||
case 'help':
|
case 'help':
|
||||||
message.channel.send("Commands:\n\n**General**\n``o!help``: Display this message\n``o!pi``: Make O speak\n\n**Voice**\n``o!voice``: Make O speak for real\n``o!altvoice``: Make O speak in his alternate voice\n``o!jvoice``: Play one of O's Japanese voice lines\n``o!jaltvoice``: Play one of O's alternate Japanese voice lines\n``o!listen``: O-Bot will record your voice and send it back to you! (These recordings are NOT stored locally.)\n``o!dc``: Make O-Bot leave the voice channel\n\n**Other**\n``o!twitch``: Get link for O-Bot creator's Twitch channel\n``o!donate``: Feed O-Bot");
|
message.channel.send("Commands:\n\n**General**\n``o!help``: Display this message\n``o!pi``: Make O speak\n\n**Voice**\n``o!voice``: Make O speak for real\n``o!altvoice``: Make O speak in his alternate voice\n``o!jvoice``: Play one of O's Japanese voice lines\n``o!jaltvoice``: Play one of O's alternate Japanese voice lines\n``o!listen``: O-Bot will record your voice and send it back to you! (These recordings are NOT stored locally.)\n``o!dc``: Make O-Bot leave the voice channel\n\n**Other**\n``o!tetrio-rooms``: Show all open rooms in TETR.IO\n``o!twitch``: Get link for O-Bot creator's Twitch channel\n``o!donate``: Feed O-Bot");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// o!pi
|
// o!pi
|
||||||
@ -88,6 +95,17 @@ bot.on('message', message => {
|
|||||||
message.member.voice.channel.leave();
|
message.member.voice.channel.leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'leave':
|
||||||
|
if(!message.member.voice.channel){
|
||||||
|
message.channel.send("``o!leave`` can only be run while you are in a voice channel!");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
message.channel.send("Disconnecting!");
|
||||||
|
message.member.voice.channel.leave();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// o!randomhex
|
// o!randomhex
|
||||||
case 'randomhex':
|
case 'randomhex':
|
||||||
@ -103,6 +121,13 @@ bot.on('message', message => {
|
|||||||
case 'listen':
|
case 'listen':
|
||||||
listen(message);
|
listen(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// o!tetrio-rooms
|
||||||
|
case 'tetrio-rooms':
|
||||||
|
message.channel.startTyping();
|
||||||
|
httpGet(message, "https://tetr.io/api/rooms");
|
||||||
|
//message.channel.send("Command temporarily unavailable");
|
||||||
|
break;
|
||||||
|
|
||||||
// Invalid command
|
// Invalid command
|
||||||
default:
|
default:
|
||||||
@ -269,6 +294,52 @@ async function listen(message){
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function printRooms(message, jsonInput){
|
||||||
|
var additionalText = "";
|
||||||
|
var roomList = "";
|
||||||
|
var roomState = "";
|
||||||
|
roomStats = JSON.parse(jsonInput);
|
||||||
|
message.channel.send("Room list:");
|
||||||
|
for(i in roomStats.rooms){
|
||||||
|
additionalText = "";
|
||||||
|
if(roomStats.rooms[i].meta.userlimit>0){
|
||||||
|
additionalText = "/" + roomStats.rooms[i].meta.userlimit;
|
||||||
|
}
|
||||||
|
if(roomStats.rooms[i].playercount > roomStats.rooms[i].playingplayers){
|
||||||
|
additionalText = additionalText + " " + "+" + (roomStats.rooms[i].playercount - roomStats.rooms[i].playingplayers);
|
||||||
|
}
|
||||||
|
roomList = roomList + "\n" + roomStats.rooms[i].meta.name + " -- " + roomStats.rooms[i].playingplayers + additionalText + "\n" + roomStats.rooms[i].state + "\nhttps://tetr.io/#" + roomStats.rooms[i].id + "\n\n";
|
||||||
|
}
|
||||||
|
message.channel.send(roomList);
|
||||||
|
message.channel.stopTyping();
|
||||||
|
|
||||||
|
//console.log(jsonInput);
|
||||||
|
//console.log(roomStats.rooms);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function httpGet(message, URL)
|
||||||
|
{
|
||||||
|
var xmlHttp = new XMLHttpRequest();
|
||||||
|
xmlHttp.open( "GET", URL, true);
|
||||||
|
xmlHttp.setRequestHeader("Authorization", "Bearer " + auth.tetrio_token);
|
||||||
|
xmlHttp.onload = function(e){
|
||||||
|
if(xmlHttp.readyState === 4){
|
||||||
|
if(xmlHttp.status === 200){
|
||||||
|
printRooms(message, xmlHttp.responseText);
|
||||||
|
} else{
|
||||||
|
console.error(xmlHttp.statusText);
|
||||||
|
message.channel.stopTyping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xmlHttp.onerror = function (e){
|
||||||
|
console.error(xmlHttp.statusText);
|
||||||
|
message.channel.stopTyping();
|
||||||
|
};
|
||||||
|
xmlHttp.send( null );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bot.login(auth.token);
|
bot.login(auth.token);
|
||||||
|
1269
package-lock.json
generated
Normal file
1269
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,11 +8,13 @@
|
|||||||
"@discordjs/opus": "^0.1.0",
|
"@discordjs/opus": "^0.1.0",
|
||||||
"bufferutil": "^4.0.1",
|
"bufferutil": "^4.0.1",
|
||||||
"discord.js": "^12.0.2",
|
"discord.js": "^12.0.2",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
"erlpack": "github:discordapp/erlpack",
|
"erlpack": "github:discordapp/erlpack",
|
||||||
"ffmpeg-static": "^3.0.0",
|
"ffmpeg-static": "^3.0.0",
|
||||||
"install-peerdeps": "^2.0.1",
|
"install-peerdeps": "^2.0.1",
|
||||||
"install-peers": "^1.0.3",
|
"install-peers": "^1.0.3",
|
||||||
"libsodium-wrappers": "^0.7.6",
|
"libsodium-wrappers": "^0.7.6",
|
||||||
|
"xmlhttprequest": "^1.8.0",
|
||||||
"zlib-sync": "^0.1.6"
|
"zlib-sync": "^0.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user