Skip to content

Commit

Permalink
Testing out emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Aug 15, 2021
1 parent b4cb5dd commit 99b5289
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ node_modules/

# log files
.log

.env
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/
require('dotenv').config()

// Config file
const config = require('./src/data/config.json');
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"canvas": "^2.6.1",
"dblapi.js": "^2.4.0",
"dd-trace": "^0.31.4",
"dotenv": "^10.0.0",
"eris-sharder": "github:ChristopherBThai/eris-sharder#093e114e1f77882479aca204f3120a6ba6639699",
"erlpack": "github:abalabahaha/erlpack",
"eventemitter3": "^4.0.4",
Expand Down
1 change: 0 additions & 1 deletion src/commands/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Command {

// Make sure user accepts rules first
if (!(await acceptedRules(this.main, interaction))) {
// TODO check if this works
executeCommand(this.main, initParam(interaction, "rule", [], this.main));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commandList/admin/captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = new CommandInterface({
dm:true,

execute: async function(p){
let {url, text, buffer} = await captcha({}, p.msg.author);
let {url, text, buffer} = await captcha.gen({}, p.msg.author);
if (url) {
p.send(url);
} else {
Expand Down
99 changes: 99 additions & 0 deletions src/commands/commandList/social/discordplays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../CommandInterface.js');

const warnEmoji = '⚠️';

module.exports = new CommandInterface({

alias:["discordplays","twitchplays", "emulator"],

args:"",

desc:"",

example:[],

related:[],

permissions:["sendMessages", "embedLinks"],

group:["social"],

cooldown: 10000,

execute: async function (p) {
let content = `${warnEmoji} **|** This is still a work in progress. The emulator will reset once everything goes live`
+ `\n${p.config.emoji.blank} **|** AGAIN, THIS COMMAND IS STILL A WORK IN PROGRESS!!`
+ `\n${p.config.emoji.blank} **|** https://www.twitch.tv/owobotplays`;
let components = [
{
type: 1,
components: [
{
type: 2,
style: 1,
label: 'A',
custom_id: "emulator_a"
},
{
type: 2,
style: 1,
label: '▲',
custom_id: "emulator_up",
},
{
type: 2,
style: 1,
label: 'B',
custom_id: "emulator_b"
},
{
type: 2,
style: 1,
label: 'START',
custom_id: "emulator_start"
}
]
},
{
type: 1,
components: [
{
type: 2,
style: 1,
label: '◄',
custom_id: "emulator_left"
},
{
type: 2,
style: 1,
label: '▼',
custom_id: "emulator_down"
},
{
type: 2,
style: 1,
label: '►',
custom_id: "emulator_right"
},
{
type: 2,
style: 1,
label: 'SELECT',
custom_id: "emulator_select"
}
]
}
];

await p.send({content, components});

}

});
4 changes: 3 additions & 1 deletion src/eventHandlers/rawWS.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* OwO Bot for Discord
* Copyright (C) 2019 Christopher Thai
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/
Expand All @@ -16,6 +16,8 @@ exports.handle = function(packet, id){
break;
case 3:
this.interactionCollector.interact(packet.d);
this.interactionHandlers.emit(packet.d.data.custom_id, packet.d);
break;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'a');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'b');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_down.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'down');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_left.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'left');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_right.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'right');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'select');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'start');
await ack();
}
11 changes: 11 additions & 0 deletions src/interactionHandlers/emulator_up.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

exports.handle = async function (data, ack) {
await this.socketio.streamEmit(data.member.user, 'up');
await ack();
}
33 changes: 33 additions & 0 deletions src/interactionHandlers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* OwO Bot for Discord
* Copyright (C) 2021 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/
const axios = require('axios');
const requireDir = require('require-dir');
const dir = requireDir('./');

class InteractionHandler {
constructor (main) {
this.listeners = {};
let filename = __filename.slice(__dirname.length + 1, -3);
for (let listener in dir) {
if (listener != filename) {
this.listeners[listener] = dir[listener].handle.bind(main);
}
}
}

emit (name, data) {
if (this.listeners[name]) {
const url = `https://discord.com/api/v8/interactions/${data.id}/${data.token}/callback`
const ack = () => {
return axios.post(url, { type: 6 });
}
this.listeners[name](data, ack);
}
}
}

module.exports = InteractionHandler;
4 changes: 4 additions & 0 deletions src/owo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class OwO extends Base{
// Redis pubsub to communicate with all the other shards/processes
this.pubsub = new (require('./utils/pubsub.js'))(this);

// Handles discord interaction events
this.interactionHandlers = new (require('./interactionHandlers'))(this);

// Websocket connection to our emulator server
this.socketio = new (require('./utils/socketio.js'))(this);

// Logger
Expand Down
7 changes: 3 additions & 4 deletions src/utils/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

const mysql = require('mysql');
const login = require('../../../tokens/owo-login.json');

config = {
host: login.mysql_host,
user: login.mysql_user,
password: login.mysql_pass,
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASS,
database: "owo",
supportBigNumbers: true,
multipleStatements: true,
Expand Down
9 changes: 4 additions & 5 deletions src/utils/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/

const redis = require('redis');
const login = require('../../../tokens/owo-login.json');
const sub = redis.createClient({
host: login.redis_host,
password: login.redis_pass
host: process.env.REDIS_HOST,
password: process.env.REDIS_PASS
});
const pub = redis.createClient({
host: login.redis_host,
password: login.redis_pass
host: process.env.REDIS_HOST,
password: process.env.REDIS_PASS
});

const requireDir = require('require-dir');
Expand Down
5 changes: 2 additions & 3 deletions src/utils/redis.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const redis = require('redis');
const login = require('../../../tokens/owo-login.json');
const client = redis.createClient({
host: login.redis_host,
password: login.redis_pass
host: process.env.REDIS_HOST,
password: process.env.REDIS_PASS
});

exports.incr = function(key,value=1){
Expand Down
Loading

0 comments on commit 99b5289

Please sign in to comment.