mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 14:58:14 +01:00
add questions n stuff
This commit is contained in:
parent
54ad94ed13
commit
cfd9e0636f
1 changed files with 64 additions and 1 deletions
|
@ -510,6 +510,69 @@ Web </a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<%
|
||||||
|
function isMathExpression(query) {
|
||||||
|
return /^[0-9\s\+\-\*\/\.\x]+$/.test(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
function evaluateMathExpression(expression) {
|
||||||
|
try {
|
||||||
|
return eval(expression);
|
||||||
|
} catch (error) {
|
||||||
|
return 'Invalid Expression';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentDate() {
|
||||||
|
const now = new Date();
|
||||||
|
return now.toLocaleDateString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentYear() {
|
||||||
|
return new Date().getFullYear();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTimeInTimezone(timezone) {
|
||||||
|
const now = new Date();
|
||||||
|
const options = { timeZone: timezone, timeStyle: 'medium', hour12: false };
|
||||||
|
return now.toLocaleTimeString('en-US', options);
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = q.toLowerCase().trim();
|
||||||
|
let answer = '';
|
||||||
|
|
||||||
|
if (isMathExpression(query)) {
|
||||||
|
answer = evaluateMathExpression(query);
|
||||||
|
} else if (query.includes('date') || query.includes('what date is it')) {
|
||||||
|
answer = getCurrentDate();
|
||||||
|
} else if (query.includes('year') || query.includes('what year is it')) {
|
||||||
|
answer = getCurrentYear();
|
||||||
|
} else if (query.includes('what time is it in')) {
|
||||||
|
const timezone = query.split('what time is it in')[1].trim();
|
||||||
|
try {
|
||||||
|
answer = getTimeInTimezone(timezone);
|
||||||
|
} catch (error) {
|
||||||
|
answer = 'Invalid Timezone';
|
||||||
|
}
|
||||||
|
} else if (query.includes('what time is it')) {
|
||||||
|
answer = new Date().toLocaleTimeString();
|
||||||
|
} else if (query.includes('day') || query.includes('what day is it')) {
|
||||||
|
const now = new Date();
|
||||||
|
const options = { weekday: 'long' };
|
||||||
|
answer = now.toLocaleDateString(undefined, options);
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<% if (answer) { %>
|
||||||
|
<div class="container">
|
||||||
|
<h2 style="font-family: 'PokeTube Flex';font-size: large;text-align: left;font-stretch: ultra-expanded; font-weight: 1000; margin-bottom: -0.1em;">
|
||||||
|
Answer to ur question
|
||||||
|
</h2>
|
||||||
|
<span style="font-size: 7em; margin-bottom: 3em; text-align: left !important; margin-right: 7em;">
|
||||||
|
<%= answer %>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
const searchStrings = [
|
const searchStrings = [
|
||||||
|
|
Loading…
Reference in a new issue