mirror of
https://git.haroon.hackclub.app/haroon/osu-leaderboard.git
synced 2024-11-14 01:09:36 +00:00
stuff
This commit is contained in:
parent
02867679f7
commit
4abe8ac1cc
1 changed files with 91 additions and 9 deletions
98
index.ts
98
index.ts
|
@ -836,10 +836,30 @@ app.command('/osu-eval', async (ctx) => {
|
||||||
app.command('/osu-search', async (ctx) => {
|
app.command('/osu-search', async (ctx) => {
|
||||||
await ctx.ack();
|
await ctx.ack();
|
||||||
|
|
||||||
|
const me = cache.find(user => user.slackId == ctx.context.userId);
|
||||||
|
|
||||||
|
if (!me) {
|
||||||
|
return ctx.respond({
|
||||||
|
response_type: 'ephemeral',
|
||||||
|
text: `Hey <@${ctx.context.userId}>, you haven't linked your osu! account to your Slack account. Run /osu-link and then run this command.`,
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `Hey <@${ctx.context.userId}>, you haven't linked your osu! account to your Slack account. Run \`/osu-link\` and then run this command.`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ctx.client.views.open({
|
ctx.client.views.open({
|
||||||
trigger_id: ctx.payload.trigger_id,
|
trigger_id: ctx.payload.trigger_id,
|
||||||
view: {
|
view: {
|
||||||
"type": "modal",
|
"type": "modal",
|
||||||
|
"callback_id": "search",
|
||||||
|
private_metadata: ctx.payload.channel_id,
|
||||||
"title": {
|
"title": {
|
||||||
"type": "plain_text",
|
"type": "plain_text",
|
||||||
"text": "Search for a beatmap",
|
"text": "Search for a beatmap",
|
||||||
|
@ -940,32 +960,32 @@ app.command('/osu-search', async (ctx) => {
|
||||||
// @ts-expect-error initial_option does exist and work.
|
// @ts-expect-error initial_option does exist and work.
|
||||||
{
|
{
|
||||||
"type": "actions",
|
"type": "actions",
|
||||||
"block_id": "rating",
|
"block_id": "ranked",
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "radio_buttons",
|
"type": "radio_buttons",
|
||||||
"initial_option": {
|
"initial_option": {
|
||||||
"text": {
|
"text": {
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": "*Unranked*"
|
"text": "*Ranked*"
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": "Maps that will not give you Performance Points"
|
"text": "Maps that will give you Performance Points"
|
||||||
},
|
},
|
||||||
"value": "unranked"
|
"value": "ranked"
|
||||||
},
|
},
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"text": {
|
"text": {
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": "*Unranked*"
|
"text": "*Graveyard*"
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": "Maps that will not give you Performance Points"
|
"text": "Maps that were previously ranked and gave you Performance Points"
|
||||||
},
|
},
|
||||||
"value": "unranked"
|
"value": "graveyard"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"text": {
|
"text": {
|
||||||
|
@ -990,7 +1010,7 @@ app.command('/osu-search', async (ctx) => {
|
||||||
"value": "loved"
|
"value": "loved"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"action_id": "rating"
|
"action_id": "ranked"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -999,6 +1019,68 @@ app.command('/osu-search', async (ctx) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.view("search", async (ctx) => {
|
||||||
|
await ctx.ack();
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
keywords: ctx.payload.state.values["keywords"]["keywords"]?.value || "",
|
||||||
|
rating: ctx.payload.state.values["rating"]["rating"]?.value || "",
|
||||||
|
gamemode: ctx.payload.state.values["gamemode"]["gamemode"].selected_option!.value,
|
||||||
|
ranked: ctx.payload.state.values["ranked"]["ranked"].selected_option!.value,
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL("https://osu.ppy.sh/api/v2/beatmapsets/search");
|
||||||
|
|
||||||
|
url.searchParams.set("e", "")
|
||||||
|
url.searchParams.set("c", "")
|
||||||
|
url.searchParams.set("g", "")
|
||||||
|
url.searchParams.set("l", "")
|
||||||
|
url.searchParams.set("m", ["osu", "taiko", "fruits", "mania"].indexOf(options.gamemode).toString())
|
||||||
|
url.searchParams.set("nsfw", "")
|
||||||
|
url.searchParams.set("played", "")
|
||||||
|
url.searchParams.set("q", options.keywords)
|
||||||
|
url.searchParams.set("r", "")
|
||||||
|
url.searchParams.set("sort", "")
|
||||||
|
url.searchParams.set("s", options.ranked);
|
||||||
|
|
||||||
|
const data = await fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${await getAccessToken(ctx.context.userId!)}`
|
||||||
|
}
|
||||||
|
}).then(res => res.json());
|
||||||
|
|
||||||
|
const set = data.beatmapsets[0];
|
||||||
|
|
||||||
|
return ctx.client.chat.postMessage({
|
||||||
|
channel: ctx.view.private_metadata,
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "context",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "mrkdwn",
|
||||||
|
"text": `<@${ctx.context.userId}> searched for a map`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"text": {
|
||||||
|
"type": "mrkdwn",
|
||||||
|
"text": `*Beatmap:* ${set.title_unicode} - ${set.artist_unicode}\n*Mapper:* ${set.creator}\n\n<https://osu.ppy.sh/beatmapsets/${set.id}|*View this set on the osu! website*>`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "image",
|
||||||
|
"image_url": set.covers.card,
|
||||||
|
"alt_text": "beatmap card"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
receiver.router.get('*', (req, res) => {
|
receiver.router.get('*', (req, res) => {
|
||||||
res.redirect(`https://osu.ppy.sh${req.path}`)
|
res.redirect(`https://osu.ppy.sh${req.path}`)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue