Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #496 from langningchen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Chen LangNing authored Sep 23, 2023
2 parents b037ee2 + 32cb9ec commit 7438f3e
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 73 deletions.
20 changes: 9 additions & 11 deletions Server/Source/Process.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Result, ThrowErrorIfFailed } from "./Result";
import { Database } from "./Database";
import MD5 from "crypto-js/md5";
import { Output } from "./Output";
import { CaptchaSecretKey } from "./Secret"
import * as cheerio from "cheerio";
import { CaptchaSecretKey } from "./Secret";
import { CheerioAPI, load } from "cheerio";
import MD5 from "crypto-js/md5";

export class Process {
private AdminUserList: Array<string> = ["chenlangning", "zhuchenrui2", "shanwenxiao"];
Expand Down Expand Up @@ -54,9 +54,9 @@ export class Process {
this.SessionID = Data["SessionID"];
this.Username = Data["Username"];
// return new Result(true, "令牌检测跳过");

let tokenHash:string = MD5(this.SessionID).toString();
let CurrentSessionData = ThrowErrorIfFailed(await this.XMOJDatabase.Select("phpsessid", ["user_id", "create_time"], {
token: MD5(this.SessionID)
token: tokenHash
}));
if (CurrentSessionData.toString() !== "") {
if (CurrentSessionData[0]["user_id"] === this.Username &&
Expand All @@ -65,7 +65,7 @@ export class Process {
}
else {
ThrowErrorIfFailed(await this.XMOJDatabase.Delete("phpsessid", {
token: this.SessionID
token: tokenHash
}));
Output.Log("Session " + this.SessionID + " expired");
}
Expand Down Expand Up @@ -96,14 +96,12 @@ export class Process {
"Username : \"" + this.Username + "\"\n");
return new Result(false, "令牌不匹配");
}

ThrowErrorIfFailed(await this.XMOJDatabase.Insert("phpsessid", {
token: MD5(this.SessionID),
token: tokenHash,
user_id: this.Username,
create_time: new Date().getTime()
}));
Output.Log("Record session: " + this.SessionID + " for " + this.Username);

return new Result(true, "令牌匹配");
}
public IfUserExist = async (Username: string): Promise<Result> => {
Expand Down Expand Up @@ -173,7 +171,7 @@ export class Process {
.then((Response) => {
return Response.text();
}).then((Response) => {
let ParsedDocument: cheerio.CheerioAPI = cheerio.load(Response);
let ParsedDocument: CheerioAPI = load(Response);
let ResultTable = ParsedDocument("#result-tab");
if (ResultTable.length == 0) {
Output.Error("Get problem score failed: Cannot find table element\n" +
Expand Down Expand Up @@ -845,7 +843,7 @@ export class Process {
StdCode = "这道题没有标程(即用户std没有AC这道题)";
return;
}
let ParsedDocument: cheerio.CheerioAPI = cheerio.load(Response);
let ParsedDocument: CheerioAPI = load(Response);
let SubmitTable = ParsedDocument("#problemstatus");
if (SubmitTable.length == 0) {
Output.Error("Get Std code failed: Cannot find submit table\n" +
Expand Down
2 changes: 1 addition & 1 deletion Server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"dependencies": {
"cheerio": "^1.0.0-rc.12",
"cryptojs": "^2.5.3"
"crypto-js": "^4.1.1"
}
}
34 changes: 34 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,40 @@
"Description": "编辑回复时提供预览"
}
]
},
"0.3.169": {
"UpdateDate": 1695455555937,
"Prerelease": true,
"UpdateContents": [
{
"PR": 491,
"Description": "忽略提醒后立刻不显示该提醒"
}
]
},
"0.3.170": {
"UpdateDate": 1695469445405,
"Prerelease": true,
"UpdateContents": [
{
"PR": 494,
"Description": "将讨论中的 @ 放在前端渲染"
}
]
},
"0.3.171": {
"UpdateDate": 1695476533444,
"Prerelease": false,
"UpdateContents": [
{
"PR": 491,
"Description": "忽略提醒后立刻不显示该提醒"
},
{
"PR": 494,
"Description": "将讨论中的 @ 放在前端渲染"
}
]
}
}
}
128 changes: 85 additions & 43 deletions Update/AutoLabel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as github from '@actions/github';

const TrustedUsers= [
const TrustedUsers = [
"langningchen",
"boomzero",
"PythonSmall-Q"
Expand Down Expand Up @@ -35,6 +35,7 @@ const LabelList = [
"working-on-it"
];


let Data = github.context.payload.comment.body;
let Octokit = github.getOctokit(process.argv[2]);
let Owner = github.context.repo.owner;
Expand All @@ -49,68 +50,109 @@ console.log("IssueNumber: " + IssueNumber);
console.log("CommentID : " + CommentID);
console.log("User : " + User);

const AddLabel = (Label) => {
if (github.context.payload.issue.labels.find((label) => label.name === Label)) {
console.log("Label " + Label + " already exists");
return false;
}
if (!LabelList.includes(Label)) {
console.log("Label " + Label + " not exists");
return false;
}
console.log("Add label " + Label);
Octokit.issues.addLabels({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
labels: [Label]
});
return true;
};
const RemoveLabel = (Label) => {
if (!github.context.payload.issue.labels.find((label) => label.name === Label)) {
console.log("Label " + Label + " not exists");
return false;
}
console.log("Remove label " + Label);
Octokit.issues.removeLabel({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
name: Label
});
return true;
};

if (!TrustedUsers.includes(User)) {
console.log("Not trusted user " + User);
process.exit(0);
}

let NewData = Data.replaceAll(/\/-[a-zA-Z-]+/g, (match) => {
console.log("Found command " + match);
let Label = match.substring(2);
if (github.context.payload.issue.labels.find((label) => label.name === Label)) {
console.log("Remove label " + Label);
Octokit.issues.removeLabel({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
name: Label
});
return "";
}
return match;
});

NewData = NewData.replaceAll(/\/[a-zA-Z-]+/g, (match) => {
let NewData = Data.replaceAll(/\/[a-zA-Z-_]+/g, (match) => {
console.log("Found command " + match);
let Label = match.substring(1);
if (LabelList.includes(Label)) {
console.log("Add label " + Label);
Octokit.issues.addLabels({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
labels: [Label]
});
return "";
if (Label.startsWith("-")) {
Label = Label.substring(1);
if (RemoveLabel(Label)) {
return "";
}
} else {
if (AddLabel(Label)) {
if (Label === "needs-triage") {
Octokit.issues.addAssignees({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
assignees: [Owner]
});
}
else if (Label === "wontfix" || Label === "duplicate" || Label === "invalid") {
Octokit.issues.update({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
state: "closed"
});

RemoveLabel("good-first-issue");
RemoveLabel("hacktoberfest-accepted");
RemoveLabel("help-wanted");
RemoveLabel("investigating");
RemoveLabel("needs-triage");
RemoveLabel("priority-high");
RemoveLabel("priority-low");
RemoveLabel("question");
RemoveLabel("review-needed");
RemoveLabel("server");
RemoveLabel("working-on-it");
}
return "";
}
}
return match;
});

if (NewData === "") {
NewData = "[]()";
if (User === "langningchen") {
if (RemoveLabel("needs-triage")) {
AddLabel("investigating");
}
}

console.log("NewData : " + NewData);

if (NewData === Data) {
console.log("No label modified");
}
else {
} else if (NewData.trim() === "") {
Octokit.issues.deleteComment({
owner: Owner,
repo: Repo,
comment_id: CommentID
});
} else {
Octokit.issues.updateComment({
owner: Owner,
repo: Repo,
comment_id: CommentID,
body: NewData
});
}

if (User === "langningchen") {
if (github.context.payload.issue.labels.find((label) => label.name === "need-triage")) {
console.log("Remove label need-triage");
Octokit.issues.removeLabel({
owner: Owner,
repo: Repo,
issue_number: IssueNumber,
name: "need-triage"
});
}
}
Loading

0 comments on commit 7438f3e

Please sign in to comment.