commit 0f444c61bd9db375092915073364a06b9eb32d83
parent 086778e0c93515289372da794339ac5017789022
Author: Agastya Chandrakant <acagastya@outlook.com>
Date: Thu, 4 Jun 2020 21:39:03 +0530
add way of getting time
Diffstat:
5 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/irc.js b/irc.js
@@ -1,6 +1,6 @@
const irc = require('irc');
const fetch = require('node-fetch');
-const moment = require('moment');
+const moment = require('moment-timezone');
const {
admins,
@@ -13,7 +13,13 @@ const {
URAPI,
} = require('./config');
-const { fetchData, fullUrl, getFullLink, getFullTemplate } = require('./utils');
+const {
+ fetchData,
+ fullUrl,
+ getFullLink,
+ getFullTemplate,
+ sayTime,
+} = require('./utils');
const { fallback, reset, short } = require('./promUrlShortener');
@@ -86,6 +92,7 @@ function groupChat(sender, channel, msg) {
if (msg.includes(`${botName} !RQ`)) announceRQ(sender, channel);
if (msg.includes(`${botName} !FB`)) fallback();
if (msg.includes(`${botName} !TRY`)) reset();
+ if (msg.includes(`${botName} !time`)) sayTime(msg, client, channel);
const regex1 = /\[{2}(.*?)\]{2}/g;
const regex2 = /\{{2}(.*?)\}{2}/g;
const links = msg.match(regex1);
diff --git a/package.json b/package.json
@@ -1,7 +1,7 @@
{
"dependencies": {
"irc": "^0.5.2",
- "moment": "^2.26.0",
+ "moment-timezone": "^0.5.31",
"node-fetch": "^2.6.0",
"request": "^2.88.2",
"tinyurl": "^1.1.5"
diff --git a/time.js b/time.js
@@ -0,0 +1,5 @@
+const timezones = new Map();
+
+timezones.set('UTC', 'UTC');
+
+module.exports = timezones;
diff --git a/utils.js b/utils.js
@@ -1,6 +1,8 @@
const fetch = require('node-fetch');
const { shortURL, URL } = require('./config');
const TUrl = require('tinyurl');
+const moment = require('moment-timezone');
+const timezones = require('./time');
async function fetchData(URI) {
const res = {};
@@ -41,9 +43,19 @@ function getFullTemplate(template) {
return `${URL}Template:${word}`;
}
+function sayTime(msg, client, channel) {
+ const user = msg.split(' ').filter(Boolean)[2];
+ const timezone = timezones.get(user) || 'UTC';
+ let time;
+ time = moment().tz(timezone).format('HH:mm MMM DD');
+ if (timezone == 'UTC') time += ' UTC';
+ client.say(channel, time);
+}
+
module.exports = {
fetchData,
fullUrl,
getFullLink,
getFullTemplate,
+ sayTime,
};
diff --git a/yarn.lock b/yarn.lock
@@ -225,7 +225,14 @@ mime-types@^2.1.12, mime-types@~2.1.19:
dependencies:
mime-db "1.44.0"
-moment@^2.26.0:
+moment-timezone@^0.5.31:
+ version "0.5.31"
+ resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.31.tgz#9c40d8c5026f0c7ab46eda3d63e49c155148de05"
+ integrity sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==
+ dependencies:
+ moment ">= 2.9.0"
+
+"moment@>= 2.9.0":
version "2.26.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.26.0.tgz#5e1f82c6bafca6e83e808b30c8705eed0dcbd39a"
integrity sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw==