Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pwnyaa: AlpacaHack 対応 #931

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions achievements/achievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,20 @@ const achievements: Achievement[] = [
condition: 'ksnctfを全完する',
category: 'pwnyaa',
},
{
id: 'pwnyaa-ah-half',
difficulty: 'hard',
title: 'アルパカかわいい!',
condition: 'AlpacaHackで半分以上の問題を解く',
category: 'pwnyaa',
},
{
id: 'pwnyaa-ah-complete',
difficulty: 'professional',
title: 'しば犬かわいい!',
condition: 'AlpacaHackを全完する',
category: 'pwnyaa',
},

// anime

Expand Down
5 changes: 5 additions & 0 deletions pwnyaa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {unlock} from '../achievements/index.js';
import logger from '../lib/logger';
import type {SlackInterface} from '../lib/slack';
import {getMemberIcon, getMemberName} from '../lib/slackUtils';
import {fetchChallsAH, fetchUserProfileAH, findUserByNameAH} from './lib/AHManager';
import {Contest, User, SolvedInfo} from './lib/BasicTypes';
import {fetchChallsCH, fetchUserProfileCH, findUserByNameCH} from './lib/CHManager';
import {fetchChallsKSN, fetchUserProfileKSN, findUserByNameKSN} from './lib/KSNManager';
Expand Down Expand Up @@ -36,12 +37,14 @@ export const TW_ID = 0;
export const XYZ_ID = 1;
export const CH_ID = 2;
export const KSN_ID = 3;
export const AH_ID = 4;

const CONTESTS: Contest[] = [
{url: 'https://pwnable.xyz', id: XYZ_ID, title: 'pwnable.xyz', alias: ['xyz', 'pnwable.xyz'], achievementStr: 'xyz', fetchUserProfile: fetchUserProfileXYZ, findUserByName: findUserByNameXYZ, fetchChalls: fetchChallsXYZ, numChalls: 0, joiningUsers: []},
{url: 'https://pwnable.tw', id: TW_ID, title: 'pwnable.tw', alias: ['tw', 'pwnable.tw'], achievementStr: 'tw', fetchUserProfile: fetchUserProfileTW, findUserByName: findUserByNameTW, fetchChalls: fetchChallsTW, numChalls: 0, joiningUsers: []},
{url: 'https://cryptohack.org', id: CH_ID, title: 'cryptohack', alias: ['cryptohack', 'ch'], achievementStr: 'ch', fetchUserProfile: fetchUserProfileCH, findUserByName: findUserByNameCH, fetchChalls: fetchChallsCH, numChalls: 0, joiningUsers: []},
{url: 'https://ksnctf.sweetduet.info', id: KSN_ID, title: 'ksnctf', alias: ['ksn', 'ksnctf'], achievementStr: 'ksn', fetchUserProfile: fetchUserProfileKSN, findUserByName: findUserByNameKSN, fetchChalls: fetchChallsKSN, numChalls: 0, joiningUsers: []},
{url: 'https://alpacahack.com', id: AH_ID, title: 'AlpacaHack', alias: ['ah', 'alpacahack', 'alpaca'], achievementStr: 'ah', fetchUserProfile: fetchUserProfileAH, findUserByName: findUserByNameAH, fetchChalls: fetchChallsAH, numChalls: 0, joiningUsers: []},
];

const UPDATE_INTERVAL = 12;
Expand Down Expand Up @@ -72,6 +75,8 @@ const getContestColor = (ctfId: number) => {
return '#0099ff';
case KSN_ID:
return '#99cc00';
case AH_ID:
return '#873e23';
default:
return '#000000';
}
Expand Down
82 changes: 82 additions & 0 deletions pwnyaa/lib/AHManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// AlpacaHack

import axios from "axios";
import { Challenge, SolvedInfo, Profile } from "./BasicTypes";

const client = axios.create({
withCredentials: false,
});

export const fetchChallsAH = async function (): Promise<Challenge[]> {
try {
const { data: json } = await client.get(
"https://alpacahack.com/challenges?_data=routes%2F_root.challenges",
{
headers: {},
}
);
return json.challenges.map(
(chall: any): Challenge => ({
id: "?", // not available
name: chall.name,
score: 0, // not available
})
);
} catch {
return null;
}
};

export const fetchUserProfileAH = async function (
userId: string
): Promise<Profile> {
try {
const { data: json } = await client.get(
`https://alpacahack.com/users/${userId}?_data=routes%2F_root.users_.%24userName`,
{
headers: {},
}
);
return {
username: json.name,
country: json.country,
rank: "?",
score: json.submissions
.filter((sub: any) => sub.isCorrect)
.length.toString(),
comment: "",
registeredAt: "", // not available
solvedChalls: json.submissions
.filter((sub: any) => sub.isCorrect)
.map(
(sub: any): SolvedInfo => ({
id: "", // not available
solvedAt: new Date(sub.createdAt.value),
name: sub.challenge.name,
score: 0, // not available
})
),
};
} catch {
return null;
}
};

export const findUserByNameAH = async function (
username: string
): Promise<{ userid: string; name: string }> {
try {
const { data: json } = await client.get(
`https://alpacahack.com/users/${username}?_data=routes%2F_root.users_.%24userName`,
{
headers: {},
}
);
return {
userid: json.name,
name: json.name,
};
} catch {
return null;
}
};
Loading