Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Adivise committed May 11, 2023
1 parent 901d7a8 commit 4147de9
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 37 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@ Copy or Rename `config.json.example` to `config.json` and fill out the values:
"password": "YOUR_IRC_PASSWORD",
"apiKey": "YOUR_API_KEY"
},
"twitch": {
"connection": {
"reconnect": true,
"secure": true
},
"identity": {
"username": "Nanotect_",
"password": "YOUR_TMI_OAUTH"
},
"channels": ["nanotect_"]
"mode": 0, // 0 = Standard, 1 = Taiko, 2 = Catch, 3 = Mania
"username": "Nanotect_",
"password": "YOUR_TMI_OAUTH"
"channels": { // "TWITCHNAME": "IGN"
"nanotect_": "Suntury"
}
}
```
Expand Down
15 changes: 5 additions & 10 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
"password": "YOUR_IRC_PASSWORD",
"apiKey": "YOUR_API_KEY"
},
"twitch": {
"connection": {
"reconnect": true,
"secure": true
},
"identity": {
"username": "Nanotect_",
"password": "YOUR_TMI_OAUTH"
},
"channels": ["nanotect_"]
"mode": 0,
"username": "Nanotect_",
"password": "YOUR_TMI_OAUTH"
"channels": {
"nanotect_": "Suntury"
}
}
104 changes: 87 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,102 @@ bancho.connect().then(() => {
console.log("[INFO] Connected to Bancho!");
});

const client = new tmi.client(require("./config.json").twitch);
const client = new tmi.client({
connection: {
reconnect: true,
secure: true
},
identity: {
username: require("./config.json").username,
password: require("./config.json").password
},
channels: Object.keys(require("./config.json").channels)
});

client.connect().then(() => {
console.log("[INFO] Connected to Twitch!");

client.on("message", async (channel, tags, message, self) => {
const regex = /https:\/\/osu.ppy.sh\/(beatmapsets|beatmaps)\/(\d+)#(osu|taiko|fruits|mania)\/(\d+)/;
if (!regex.test(message)) return;
client.on("message", async (channel, tags, message, self) => {
const regex = {
beatmap_official: /https?:\/\/osu.ppy.sh\/beatmapsets\/[0-9]+\#(osu|taiko|fruits|mania)\/([0-9]+)/,
beatmap_old: /https?:\/\/(osu|old).ppy.sh\/b\/([0-9]+)/,
beatmap_alternate: /https?:\/\/osu.ppy.sh\/beatmaps\/([0-9]+)/,
beatmap_old_alternate: /https?:\/\/(osu|old).ppy.sh\/p\/beatmap\?b=([0-9]+)/,
beatmapset_official: /https?:\/\/osu.ppy.sh\/beatmapsets\/([0-9]+)/,
beatmapset_old: /https?:\/\/(osu|old).ppy.sh\/s\/([0-9]+)/,
beatmapset_old_alternate: /https?:\/\/(osu|old).ppy.sh\/p\/beatmap\?s=([0-9]+)/,
};

let matchedRegex = null;
for (const key in regex) {
if (regex[key].test(message)) {
matchedRegex = regex[key];
break;
}
}

if (!matchedRegex) return;

const beatmapId = message.match(regex)[4];
const { beatmaps } = new Client(require("./config.json").bancho.apiKey);
const beatmap = await beatmaps.getByBeatmapId(beatmapId);
const beatmapId = message.match(matchedRegex)[2];
const { beatmaps } = new Client(require("./config.json").bancho.apiKey);
const beatmap = await beatmaps.getByBeatmapId(beatmapId);

if (beatmap.length == 0) return client.say(channel, `@${tags.username}, Beatmap not found!`);
if (beatmap[0].mode != 0) return client.say(channel, `@${tags.username}, Beatmap is not in osu!standard mode!`);
if (beatmap.length == 0) return client.say(channel, `@${tags.username}, Beatmap not found!`);
if (beatmap[0].mode != require("./config.json").mode) return client.say(channel, `@${tags.username}, Beatmap is not in osu!${Mode(require("./config.json").mode)} mode!`);

client.say(channel, `@${tags.username}, Your request has been sent!`);
bancho.getSelf().sendMessage(`${tags.username} -> [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${parseInt(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`)
});
client.say(channel, `${beatmap[0].title} [${Approved(beatmap)}] - Request sent!`);
await sendMsg(require("./config.json").channels[channel.replace("#", "")], `${tags.username} -> [${Approved(beatmap)}] [https://osu.ppy.sh/b/${beatmap[0].beatmap_id} ${beatmap[0].title}] (${parseInt(beatmap[0].difficultyrating).toFixed(2)}*, ${beatmap[0].bpm} BPM, ${convertSeconds(beatmap[0].total_length)}) - [https://beatconnect.io/b/${beatmap[0].beatmapset_id} [1]] [https://dl.sayobot.cn/beatmaps/download/novideo/${beatmap[0].beatmapset_id} [2]] [https://api.chimu.moe/v1/download/${beatmap[0].beatmapset_id}?n=1 [3]]`)
});
});

function convertSeconds(seconds) {
var hours = Math.floor(seconds / 3600);
seconds %= 3600;
var minutes = Math.floor(seconds / 60);
seconds = Math.floor(seconds % 60);
var hours = Math.floor(seconds / 3600);
seconds %= 3600;
var minutes = Math.floor(seconds / 60);
seconds = Math.floor(seconds % 60);

return (hours ? hours + ":" + (minutes < 10 ? "0" : "") : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
return (hours ? hours + ":" + (minutes < 10 ? "0" : "") : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
}

function Mode(mode) {
let status = ""

if (mode == 0) {
status = "Standard";
} else if (mode == 1) {
status = "Taiko";
} else if (mode == 2) {
status = "Catch";
} else if (mode == 3) {
status = "Mania";
}

return status;
}

function Approved(beatmap) {
let status = "";

if(beatmap[0].approved == -2) {
status = "Graveyard"
} else if (beatmap[0].approved == -1) {
status = "WIP"
} else if(beatmap[0].approved == 0) {
status = "Pending"
} else if (beatmap[0].approved == 1) {
status = "Ranking"
} else if (beatmap[0].approved == 2) {
status = "Approved"
} else if (beatmap[0].approved == 3) {
status = "Qualified"
} else if (beatmap[0].approved == 4) {
status = "Loved"
}

return status;
}

async function sendMsg(channel, message) {
const player = bancho.getUser(channel);
player.sendMessage(message);
}

0 comments on commit 4147de9

Please sign in to comment.