Skip to content

Commit

Permalink
Change Anything
Browse files Browse the repository at this point in the history
  • Loading branch information
Adivise committed May 20, 2022
1 parent b87f0ec commit 049b68d
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 42 deletions.
5 changes: 2 additions & 3 deletions commands/general/nowplaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module.exports = {
name: "nowplaying",
aliases: ["np"],
},
run: async (twitch, channel, tags, args) => {

run: async (client, channel, tags, args, language) => {
const { menu } = await fetch(`http://127.0.0.1:24050/json`).then(response => response.json()); //<== requirement gosumemory to working!
const title = menu.bm.metadata.title; // this all api wrapper
const ar = menu.bm.stats.AR;
Expand All @@ -20,7 +19,7 @@ module.exports = {
const mods = menu.mods.str;
const rarity = menu.bm.id;

twitch.say(channel, twitch.i18n.get("en", "nowplaying", "nowplaying_msg", {
client.say(channel, client.i18n.get(language, "nowplaying", "message", {
title: title,
ar: ar,
cs: cs,
Expand Down
4 changes: 2 additions & 2 deletions commands/general/ppfc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
name: "ppfc",
aliases: ["performancefullcombo"],
},
run: async (twitch, channel, tags, args) => {
run: async (client, channel, tags, args, language) => {
const { menu } = await fetch(`http://127.0.0.1:24050/json`).then(response => response.json()); //<== requirement run gosumemory to working!
const ppfc = menu.pp['100'];
const nightynight = menu.pp['99'];
Expand All @@ -15,7 +15,7 @@ module.exports = {
const nightysix = menu.pp['96'];
const nightyfive = menu.pp['95'];

twitch.say(channel, twitch.i18n.get("en", "nowplaying", "ppfc_msg", {
client.say(channel, client.i18n.get(language, "ppfc", "message", {
ppfc: ppfc,
nightynight: nightynight,
nightyeight: nightyeight,
Expand Down
17 changes: 5 additions & 12 deletions commands/general/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ module.exports = {
name: "request",
aliases: ["rq"],
},
run: async (twitch, channel, tags, args) => {
const { BanchoClient } = require("bancho.js");
const client = new BanchoClient({ username: twitch.config.OSU_NAME, password: twitch.config.OSU_PASS });

run: async (client, channel, tags, args, language) => {
const url = args[0]; //
if (!url) return twitch.say(channel, `@${tags.username}, Please provide a beatmap to request!`);
if (!url.includes("https://osu.ppy.sh/beatmapsets/")) return twitch.say(channel, `@${tags.username}, Please provide a beatmap link!`);
if (!url) return client.say(channel, `@${tags.username}, Please provide a beatmap to request!`);
if (!url.includes("https://osu.ppy.sh/beatmapsets/")) return client.say(channel, `@${tags.username}, Please provide a beatmap link!`);

/// Await for the client to connect to the server
await client.connect().then(() => {
// console.log("Connected to Bancho!");
const user = client.getSelf();
user.sendMessage(`Song: ${url} | Requested By: ${tags.username}`);
}).catch(console.error);
/// Send Message TO BANCHO SERVER
await client.SendMessage(language, tags.username, url);
}
}
4 changes: 2 additions & 2 deletions commands/general/skin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = {
name: "skin",
aliases: ["currentskin"],
},
run: async (twitch, channel, tags, args) => {
run: async (client, channel, tags, args, language) => {
const { settings } = await fetch(`http://127.0.0.1:24050/json`).then(response => response.json()); //<== requirement run gosumemory to working!
const skin = settings.folders.skin;

twitch.say(channel, twitch.i18n.get("en", "nowplaying", "skin_msg", {
client.say(channel, client.i18n.get(language, "skin", "message", {
skin: skin,
}));
}
Expand Down
14 changes: 8 additions & 6 deletions events/client/message.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const { PREFIX } = require("../../settings/config.js");

module.exports = async (twitch, channel, tags, message, self) => {
module.exports = async (client, channel, tags, message, self) => {
if (self) return;
if (!message.startsWith(PREFIX)) return;

const args = message.slice(PREFIX.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
const command = twitch.commands.get(cmd) || twitch.commands.get(twitch.aliases.get(cmd));
const command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));

const language = "en"

if(!command) return;

try {
if (command.ownerOnly) {
if (tags.username !== twitch.owner) {
return twitch.say(channel, `${tags.username}, You are not my owner!`);
if (tags.username !== client.owner) {
return client.say(channel, `${tags.username}, You are not my owner!`);
}
}
command.run(twitch, channel, tags, args);
command.run(client, channel, tags, args, language);
} catch (error) {
console.log(error);
return twitch.say(channel, `Something went wrong!`);
return client.say(channel, `Something went wrong!`);
}
}
17 changes: 17 additions & 0 deletions handlers/loadBancho.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// const { BanchoClient } = require("bancho.js");
const { client } = require("tmi.js");

/**
*
* @param {client} client
*/
module.exports = async (client) => {

//// Send
client.SendMessage = async function (language, user, args) {
client.bancho.getSelf().sendMessage(client.i18n.get(language, "request", "message", {
user: user,
args: args,
}));
};
}
6 changes: 3 additions & 3 deletions handlers/loadCommands.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { readdirSync } = require("fs");

module.exports = async (twitch) => {
module.exports = async (client) => {
const load = dirs => {
const commands = readdirSync(`./commands/${dirs}/`).filter(d => d.endsWith('.js'));
for (let file of commands) {
let pull = require(`../commands/${dirs}/${file}`);
twitch.commands.set(pull.config.name, pull);
if (pull.config.aliases) pull.config.aliases.forEach(a => twitch.aliases.set(a, pull.config.name));
client.commands.set(pull.config.name, pull);
if (pull.config.aliases) pull.config.aliases.forEach(a => client.aliases.set(a, pull.config.name));
};
};
["general"].forEach(x => load(x));
Expand Down
4 changes: 2 additions & 2 deletions handlers/loadEvents.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { readdirSync } = require("fs")

module.exports = async (twitch, message) => {
module.exports = async (client, message) => {
const load = dirs => {
const events = readdirSync(`./events/${dirs}/`).filter(d => d.endsWith('.js'));
for (let file of events) {
const evt = require(`../events/${dirs}/${file}`);
let eName = file.split('.')[0];
twitch.on(eName, evt.bind(null, twitch));
client.on(eName, evt.bind(null, client));
}
};
['client'].forEach(x => load(x));
Expand Down
30 changes: 21 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const tmi = require("tmi.js");
const { Collection } = require("@discordjs/collection");
const config = require("./settings/config.js");
const { I18n } = require("locale-parser");
const { BanchoClient } = require("bancho.js");

let options = {
connection: {
Expand All @@ -15,18 +16,29 @@ let options = {
channels: [config.CHANNEL],
};

console.log(`[INFO] Connecting to Twitch`);

process.on('unhandledRejection', error => console.log(error));
process.on('uncaughtException', error => console.log(error));

const twitch = new tmi.client(options);
const client = new tmi.client(options);

client.config = require("./settings/config.js");
client.owner = config.OWNER;
client.i18n = new I18n(config.LANGUAGE);

const bancho = new BanchoClient({ username: config.OSU_NAME, password: config.OSU_PASS });

client.bancho = bancho;

twitch.config = require("./settings/config.js");
twitch.owner = config.OWNER;
twitch.i18n = new I18n(twitch.config.LANGUAGE);
/// Load Twitch Package
["aliases", "commands"].forEach(x => client[x] = new Collection());
["loadCommands", "loadEvents", "loadBancho"].forEach(x => require(`./handlers/${x}`)(client));

["aliases", "commands"].forEach(x => twitch[x] = new Collection());
["loadCommands", "loadEvents"].forEach(x => require(`./handlers/${x}`)(twitch));
/// Start Bancho Client
bancho.connect().then(() => {
console.log("[INFO] Connected to Bancho!");
});

twitch.connect();
/// Start Twitch Client
client.connect().then(() => {
console.log("[INFO] Connected to Twitch!");
});
4 changes: 1 addition & 3 deletions languages/en/nowplaying.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
nowplaying_msg: "⏯ MAP: %{title} 🎮 MODS: %{mods} | %{star} ⭐ | 🔩 AR: %{ar} CS: %{cs} OD: %{od} HP: %{hp} BPM: %{bpm} | 🔗 DL: (https://osu.ppy.sh/beatmapsets/%{link}#osu/%{rarity})"
ppfc_msg: "✅ Performance Points | ⭐ 100%: %{ppfc}pp | 99%: %{nightynight}pp | 98%: %{nightyeight}pp | 97%: %{nightyseven}pp | 96%: %{nightysix}pp | 95%: %{nightyfive}pp "
skin_msg: "🔧 Current Skin: %{skin}"
message: "⏯ MAP: %{title} 🎮 MODS: %{mods} | %{star} ⭐ | 🔩 AR: %{ar} CS: %{cs} OD: %{od} HP: %{hp} BPM: %{bpm} | 🔗 DL: (https://osu.ppy.sh/beatmapsets/%{link}#osu/%{rarity})"
1 change: 1 addition & 0 deletions languages/en/ppfc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message: "✅ Performance Points | ⭐ 100%: %{ppfc}pp | 99%: %{nightynight}pp | 98%: %{nightyeight}pp | 97%: %{nightyseven}pp | 96%: %{nightysix}pp | 95%: %{nightyfive}pp "
1 change: 1 addition & 0 deletions languages/en/request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message: "Song: %{args} Requested By: %{user}"
1 change: 1 addition & 0 deletions languages/en/skin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message: "🔧 Current Skin: %{skin}"

0 comments on commit 049b68d

Please sign in to comment.