-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
birajrai
committed
Oct 31, 2022
1 parent
9fa652b
commit 240d25c
Showing
58 changed files
with
20,761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.weight = exports.autoComplete = exports.request = void 0; | ||
const math_1 = __importDefault(require("../../math")); | ||
async function request(query) { | ||
const answer = (0, math_1.default)(query); | ||
if (answer && answer != query) | ||
return { | ||
answer: { | ||
content: answer, | ||
}, | ||
}; | ||
else | ||
return {}; | ||
} | ||
exports.request = request; | ||
async function autoComplete(query) { | ||
const answer = (0, math_1.default)(query); | ||
if (answer) | ||
return ["= " + answer]; | ||
else | ||
return []; | ||
} | ||
exports.autoComplete = autoComplete; | ||
exports.weight = 1.1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const base64Regex = /^b(?:ase)?64( encode| decode|)(?:\s+)(.+)$/i; | ||
function base64Encode(string) { | ||
try { | ||
return Buffer.from(string).toString("base64"); | ||
} | ||
catch { | ||
return null; | ||
} | ||
} | ||
function base64Decode(string) { | ||
try { | ||
let decoded = Buffer.from(string, "base64").toString("utf8"); | ||
if (decoded.includes("�")) | ||
return null; | ||
else | ||
return decoded; | ||
} | ||
catch { | ||
return null; | ||
} | ||
} | ||
async function request(query) { | ||
const regexMatch = query.match(base64Regex); | ||
if (!regexMatch) | ||
return {}; | ||
const intent = regexMatch[1].trim().toLowerCase(); | ||
const string = regexMatch[2].trim(); | ||
let encoded; | ||
let decoded; | ||
if (intent == "encode") { | ||
encoded = base64Encode(string); | ||
} | ||
else if (intent == "decode") { | ||
decoded = base64Decode(string); | ||
} | ||
else { | ||
encoded = base64Encode(string); | ||
decoded = base64Decode(string); | ||
} | ||
if (!encoded && !decoded) | ||
return {}; | ||
let title; | ||
let answer; | ||
if (encoded && decoded) { | ||
title = "base64 encode & decode"; | ||
answer = `${encoded}\n\n${decoded}`; | ||
} | ||
else if (encoded) { | ||
title = "base64 encode"; | ||
answer = encoded; | ||
} | ||
else if (decoded) { | ||
title = "base64 decode"; | ||
answer = decoded; | ||
} | ||
return { | ||
answer: { | ||
title: title, | ||
content: answer, | ||
url: encoded | ||
? "https://www.base64encode.org/" | ||
: "https://www.base64decode.org/", | ||
}, | ||
}; | ||
} | ||
exports.request = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const commonWords = require("../../../src/common-words.json"); | ||
const parser_1 = require("../../parser"); | ||
const defineRegex = /^(?:define )(.+)$/i; | ||
async function parseDictionary(url, { containerPath, wordNamePath, phoneticSpellingPath, ipaSpellingPath, entryPaths, partOfSpeechPath, entryDefinitionsPath, definitionPath, definitionLabelPath, }) { | ||
const dom = await (0, parser_1.requestDom)(url); | ||
const body = dom(containerPath); | ||
const wordName = (0, parser_1.extractText)(body, wordNamePath); | ||
const phoneticSpelling = (0, parser_1.extractText)(body, phoneticSpellingPath); | ||
const ipaSpelling = (0, parser_1.extractText)(body, ipaSpellingPath); | ||
const entries = []; | ||
for (const entryEl of (0, parser_1.getElements)(body, entryPaths)) { | ||
const partOfSpeech = (0, parser_1.extractText)(entryEl, partOfSpeechPath); | ||
const entryDefinitions = []; | ||
for (const definitionEl of (0, parser_1.getElements)(entryEl, entryDefinitionsPath)) { | ||
const definition = (0, parser_1.extractText)(definitionEl, definitionPath); | ||
const label = (0, parser_1.extractText)(definitionEl, definitionLabelPath); | ||
entryDefinitions.push({ | ||
label, | ||
definition, | ||
}); | ||
} | ||
entries.push({ | ||
partOfSpeech, | ||
definitions: entryDefinitions, | ||
}); | ||
} | ||
return { | ||
word: wordName, | ||
phoneticSpelling, | ||
ipaSpelling, | ||
entries, | ||
url, | ||
}; | ||
} | ||
/** Search dictionary.com, this is kinda broken */ | ||
async function dictionaryCom(query) { | ||
return await parseDictionary("https://www.dictionary.com/browse/" + encodeURI(query), { | ||
containerPath: "section.serp-nav-button + div", | ||
wordNamePath: "section.entry-headword > div > div h1", | ||
phoneticSpellingPath: "section.entry-headword span.pron-spell-content", | ||
ipaSpellingPath: ".pron-ipa-content", | ||
entryPaths: "section.entry-headword ~ section", | ||
partOfSpeechPath: ".luna-pos", | ||
entryDefinitionsPath: "section > div > div[value], .default-content > div[value], h3 + div > div[value]", | ||
definitionPath: "div[value] > span.one-click-content:last-of-type", | ||
definitionLabelPath: ".luna-label", | ||
}); | ||
} | ||
function matchWord(query) { | ||
const regexMatch = query.match(defineRegex); | ||
if (regexMatch) | ||
return regexMatch[1]; | ||
else if (!query.includes(" ") && !commonWords.includes(query)) | ||
return query; | ||
return {}; | ||
} | ||
async function request(query) { | ||
const inputtedWord = matchWord(query); | ||
if (!inputtedWord) | ||
return {}; | ||
let { word, phoneticSpelling, ipaSpelling, entries, url } = await dictionaryCom(inputtedWord); | ||
if (!word) | ||
return {}; | ||
return { | ||
answer: { | ||
template: "dictionary", | ||
word, | ||
phoneticSpelling, | ||
ipaSpelling, | ||
entries, | ||
url, | ||
}, | ||
}; | ||
} | ||
exports.request = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const encodeDecodeRegex = /(?:hex(?:adecimal)?|base ?16) ?(encode|decode|)(?:\s+)(.+)/i; | ||
const toFromRegex = /(.+) (to|from) (?:hex(?:adecimal)?|base ?16)/i; | ||
function hexEncode(string) { | ||
try { | ||
return Buffer.from(string).toString("hex"); | ||
} | ||
catch { | ||
return null; | ||
} | ||
} | ||
function hexDecode(string) { | ||
try { | ||
let decoded = Buffer.from(string, "hex").toString("utf8"); | ||
if (decoded.includes("�")) | ||
return null; | ||
else | ||
return decoded; | ||
} | ||
catch { | ||
return null; | ||
} | ||
} | ||
function match(query) { | ||
const encodeDecodeRegexMatch = query.match(encodeDecodeRegex); | ||
if (!encodeDecodeRegexMatch) { | ||
const toFromRegexMatch = query.match(toFromRegex); | ||
if (!toFromRegexMatch) | ||
return {}; | ||
return { | ||
intent: toFromRegexMatch[2].trim().toLowerCase() === "to" ? "encode" : "decode", | ||
string: toFromRegexMatch[1].trim(), | ||
}; | ||
} | ||
return { | ||
intent: encodeDecodeRegexMatch[1].trim().toLowerCase(), | ||
string: encodeDecodeRegexMatch[2].trim(), | ||
}; | ||
} | ||
async function request(query) { | ||
const matchResponse = match(query); | ||
if (!("intent" in matchResponse)) | ||
return {}; | ||
const { intent, string } = matchResponse; | ||
let encoded = null; | ||
let decoded = null; | ||
if (intent == "encode") { | ||
encoded = hexEncode(string); | ||
} | ||
else if (intent == "decode") { | ||
decoded = hexDecode(string); | ||
} | ||
else { | ||
encoded = hexEncode(string); | ||
decoded = hexDecode(string); | ||
} | ||
if (!encoded && !decoded) | ||
return {}; | ||
let title; | ||
let answer; | ||
if (encoded && decoded) { | ||
title = "hex encode & decode"; | ||
answer = `${encoded}\n\n${decoded}`; | ||
} | ||
else if (encoded) { | ||
title = "hex encode"; | ||
answer = encoded; | ||
} | ||
else if (decoded) { | ||
title = "hex decode"; | ||
answer = decoded; | ||
} | ||
return { | ||
answer: { | ||
title: title, | ||
content: answer, | ||
}, | ||
}; | ||
} | ||
exports.request = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const lengthofRegex = /^(?:(?:how long is|len(?:gth(?: of)?)?|(?:(?:number of |how many )?char(?:acters|s) in))(.+?)|(.+?)(?:len(?:gth)))$/i; | ||
async function request(query) { | ||
const regexMatch = query.match(lengthofRegex); | ||
if (!regexMatch) | ||
return {}; | ||
const matched = regexMatch[1].trim() || regexMatch[2].trim(); | ||
return { | ||
answer: { | ||
content: `${matched} is ${matched.length} characters long`, | ||
}, | ||
}; | ||
} | ||
exports.request = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
async function request(query) { | ||
if (query.toLowerCase().includes("lorem ipsum")) | ||
return { | ||
answer: { | ||
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", | ||
}, | ||
}; | ||
else | ||
return {}; | ||
} | ||
exports.request = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const parser_1 = require("../../parser"); | ||
const cssRegex = /^(?:(?:css ([a-z-]+))|(?:([a-z-]+) css))$/i; | ||
const htmlRegex = /^(?:(?:html ([a-z-]+)(?: element)?)|(?:([a-z-]+)(?: element)? html))$/i; | ||
const apiRegex = /^(?:(?:(?:js |javascript )?([a-z ]+) api)|(?:([a-z ]+) (?:js |javascript )?api))$/i; | ||
// "js closures" | ||
const jsRegex = /^(?:(?:(?:js|javascript) ?([a-z ]+))|(?:([a-z ]+) (?:js|javascript)))$/i; | ||
// "js what are closures" | ||
const jsRegex2 = /^(?:(?:(?:js|javascript)(?: what( is|'s|s| are|'re))? ?([a-z ]+))|(?:what( is|'s|s| are|'re))? (?:([a-z ]+) (?:in )?(?:js|javascript)))$/i; | ||
async function makeSidebarResponse(urlPart) { | ||
const url = `https://developer.mozilla.org/en-US/docs/Web/${urlPart}`; | ||
const dom = (await (0, parser_1.requestDom)(url))("html"); | ||
if ((0, parser_1.extractText)(dom, "h1") === "Page not found") | ||
return {}; | ||
const firstParagraph = (0, parser_1.extractText)(dom, "article p"); | ||
if (!firstParagraph) | ||
return {}; | ||
return { | ||
sidebar: { | ||
title: (0, parser_1.extractText)(dom, "h1"), | ||
content: firstParagraph, | ||
url, | ||
}, | ||
}; | ||
} | ||
async function request(query) { | ||
var _a, _b, _c, _d, _e; | ||
let match; | ||
match = query.match(cssRegex); | ||
if (match) | ||
return await makeSidebarResponse(`CSS/${(_a = match[1]) !== null && _a !== void 0 ? _a : match[2]}`); | ||
match = query.match(htmlRegex); | ||
if (match) | ||
return await makeSidebarResponse(`HTML/Element/${(_b = match[1]) !== null && _b !== void 0 ? _b : match[2]}`); | ||
match = query.match(apiRegex); | ||
if (match) | ||
return await makeSidebarResponse(`API/${((_c = match[1]) !== null && _c !== void 0 ? _c : match[2]).replace(/ /g, "_")}`); | ||
match = query.match(jsRegex); | ||
if (match) | ||
return await makeSidebarResponse(`JavaScript/${((_d = match[1]) !== null && _d !== void 0 ? _d : match[2]).replace(/ /g, "_")}`); | ||
match = query.match(jsRegex2); | ||
if (match) | ||
return await makeSidebarResponse(`JavaScript/${((_e = match[1]) !== null && _e !== void 0 ? _e : match[2]).replace(/ /g, "_")}`); | ||
return {}; | ||
} | ||
exports.request = request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const { requestJSON } = require("../../parser"); | ||
// if you want to make this regex less cursed, good luck :) | ||
const minecraftRegex = /^(?:(?:(?:namemc) *\b(.{1,16}|[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})\b)|(?:\b(.{1,16}|[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12})\b(?:namemc)))$/i; | ||
async function requestMojang(name) { | ||
return await requestJSON("https://api.ashcon.app/mojang/v2/user/" + encodeURI(name)); | ||
} | ||
async function request(query) { | ||
const regexMatch = query.match(minecraftRegex); | ||
if (!regexMatch) | ||
return {}; | ||
let name = (regexMatch[1] || regexMatch[2]).trim(); | ||
const { error, uuid, username, username_history } = await requestMojang(name); | ||
if (error) | ||
return {}; | ||
let undashedUuid = uuid.replace(/-/g, ""); | ||
return { | ||
answer: { | ||
template: "minecraft-name", | ||
username, | ||
uuid, | ||
undasheduuid: undashedUuid, | ||
url: `https://namemc.com/${encodeURI(undashedUuid)}`, | ||
history: username_history, | ||
}, | ||
}; | ||
} | ||
exports.request = request; |
Oops, something went wrong.