Skip to content

Commit

Permalink
feat(KQM): add presence (#8162)
Browse files Browse the repository at this point in the history
* kqm

* edit logo

Signed-off-by: selvuen <[email protected]>

* oops

Signed-off-by: selvuen <[email protected]>

* add new field

* Update websites/K/KQM/presence.ts

Co-authored-by: Daniel Lau <[email protected]>
Signed-off-by: selvuen <[email protected]>

* remove iframematches

Signed-off-by: selvuen <[email protected]>

* largeimagekey

Signed-off-by: selvuen <[email protected]>

* m

Signed-off-by: selvuen <[email protected]>

* Update presence.ts

Signed-off-by: selvuen <[email protected]>

* me when the

Signed-off-by: selvuen <[email protected]>

---------

Signed-off-by: selvuen <[email protected]>
Co-authored-by: Daniel Lau <[email protected]>
  • Loading branch information
clevernt and theusaf authored Mar 12, 2024
1 parent 35f367c commit fececa9
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
22 changes: 22 additions & 0 deletions websites/K/KQM/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://schemas.premid.app/metadata/1.10",
"author": {
"id": "290820916051705868",
"name": "clevernt"
},
"service": "KQM",
"description": {
"en": "KQM is home to the best Genshin Impact guides and the most reputable theorycrafting community. Learn about your favorite Genshin Impact characters’ builds, artifacts, weapons, teams, and more!"
},
"url": "keqingmains.com",
"matches": ["*://*.keqingmains.com/*"],
"version": "1.0.0",
"logo": "https://i.imgur.com/zPaoj5v.png",
"thumbnail": "https://keqingmains.com/wp-content/uploads/2023/12/KQM_Banner-1536x254.webp",
"color": "#dab2f9",
"category": "games",
"tags": [
"genshin-impact",
"game"
]
}
134 changes: 134 additions & 0 deletions websites/K/KQM/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
const presence = new Presence({
clientId: "1215004822676312174",
});

function cleanAndCapitalize(string: string): string {
return string
.replace(/[_-]/g, " ")
.split(" ")
.map(word => word.charAt(0).toUpperCase() + word.substring(1))
.join(" ");
}

const browsingTimestamp = Math.floor(Date.now() / 1000),
characterList = [
"amber",
"barbara",
"beidou",
"bennett",
"chongyun",
"diluc",
"diona",
"eula",
"fischl",
"ganyu",
"hu_tao",
"jean",
"kaeya",
"kaedehara_kazuha",
"keqing",
"klee",
"lisa",
"mona",
"ningguang",
"noelle",
"qiqi",
"razor",
"rosaria",
"sucrose",
"tartaglia",
"anemo-traveler",
"geo-traveler",
"venti",
"xiangling",
"xiao",
"xingqiu",
"xinyan",
"yanfei",
"zhongli",
"albedo",
"kujou_sara",
"raiden_shogun",
"kamisato_ayaka",
"yoimiya",
"electro-traveler",
"sangonomiya_kokomi",
"sayu",
"aloy",
"thoma",
"itto",
"gorou",
"yunjin",
"shenhe",
"yae",
"ayato",
"shinobu",
"dendro-traveler",
"heizou",
"tighnari",
"collei",
"dori",
"candace",
"cyno",
"nilou",
"nahida",
"layla",
"faruzan",
"wanderer",
"alhaitham",
"yaoyao",
"dehya",
"mika",
"baizhu",
"kaveh",
"kirara",
"hydro-traveler",
"lyney",
"lynette",
"freminet",
"neuvillette",
"wriothesley",
"furina",
"charlotte",
"navia",
"chevreuse",
"xianyun",
"gaming",
];

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "https://i.nuuls.com/Z1rY4.png",
startTimestamp: browsingTimestamp,
},
{ pathname, host } = document.location;

if (pathname === "/") presenceData.details = "Browsing KQM";

const matchedCharacter = characterList.find(character => {
return new RegExp(
`^/(${character}|q/${character.toLowerCase()}[^/]*-quickguide)/$`
).test(pathname);
});

if (matchedCharacter) {
presenceData.details = `Reading a ${
pathname.includes("-quickguide") ? "Quick Guide" : "Guide"
}`;
presenceData.state = document.title
.replace(" - KQM", "")
.replace(" Quick Guide", "");
} else if (pathname.includes("/misc")) {
presenceData.details = "Reading a Miscellaneous Guide";
presenceData.state = document.title.replace(" - KQM", "");
} else if (host === "library.keqingmains.com") {
presenceData.details = "Browsing TCL";
presenceData.state =
cleanAndCapitalize(document.title.replace(" | KQM TCL", "")) || null;
} else if (host === "compendium.keqingmains.com") {
presenceData.details = "Browsing The Compendium";
presenceData.state = cleanAndCapitalize(pathname.substring(1)) || null;
}

presence.setActivity(presenceData);
});

0 comments on commit fececa9

Please sign in to comment.