From 318fd11d5faaa24bedaeacd2d2b13fb9f8aa3ec9 Mon Sep 17 00:00:00 2001 From: vzapo Date: Sun, 29 Dec 2019 01:41:50 +0000 Subject: [PATCH 1/4] WIP timezone command --- commands/util/timezone.js | 48 +++++++++++++++++++++++++++++++++++++++ index.js | 8 +++---- util/Utils.js | 4 ++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 commands/util/timezone.js diff --git a/commands/util/timezone.js b/commands/util/timezone.js new file mode 100644 index 0000000..9531a93 --- /dev/null +++ b/commands/util/timezone.js @@ -0,0 +1,48 @@ +const Command = require('../../structures/Command'); +const moment = require('moment-timezone'); +const {firstUpperCase} = require('../../util/Utils.js'); +const cityTimezones = require('city-timezones'); + +module.exports = class TimeCommand extends Command { + constructor(client) { + super(client, { + name: 'timenow', + aliases: ['time-zone'], + group: 'util', + memberName: 'timenow', + description: 'Responds with the current time in a particular location.', + details: '**Zones:** ', + examples: ['`!timenow America/New_York`'], + credit: [ + { + name: 'List of tz database time zones', + url: 'https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' + }, + ], + args: [ + { + key: 'timeDate', + label: 'time date', + prompt: 'Which time zone do you want to get the time of?', + type: 'string', + parse: timeDate => timeDate.replace(/ /g, '_').toLowerCase() + } + ] + }); + } + + run(msg, {timeDate }) { + + if (!moment.tz.zone(timeDate)) { + return msg.reply('Invalid time zone. Refer to .'); + } + + const time_now = moment().tz(timeDate).format('h:mm A'); + const time_zone = moment().tz(timeDate).zoneAbbr(); + const location = timeDate.split('/'); + + const place = firstUpperCase(location[0]); + const city = location[1] ? firstUpperCase(location[1]) : null; + return msg.say(`The current time in ${place}, ${city} is ${time_now} ${time_zone}.`); + } +}; \ No newline at end of file diff --git a/index.js b/index.js index 802e888..6e46ab9 100644 --- a/index.js +++ b/index.js @@ -66,11 +66,11 @@ client.on('disconnect', event => { client.on('commandRun', command => logger.info(`[COMMAND] Ran command ${command.groupID}:${command.memberName}.`)); -client.on('error', err => logger.error('[ERROR]', err)); +client.on('error', err => logger.error(err)); -client.on('warn', err => logger.warn('[WARNING]', err)); +client.on('warn', err => logger.warn(err)); -client.on('commandError', (command, err) => logger.error('[COMMAND ERROR]', command.name, err)); +client.on('commandError', (command, err) => logger.error({command:command.name, err})); client.on('message', async (msg) => { if(msg.author.bot) return; @@ -143,6 +143,6 @@ client.on('messageReactionRemove', (reaction, user) => removeMeme(reaction, user client.login(BOT_TOKEN); process.on('unhandledRejection', err => { - logger.error('[FATAL] Unhandled Promise Rejection.', err); + logger.error(err); process.exit(1); }); diff --git a/util/Utils.js b/util/Utils.js index 8f193d6..c8fdb9f 100644 --- a/util/Utils.js +++ b/util/Utils.js @@ -119,4 +119,8 @@ module.exports = class Utils { return false; } + + static firstUpperCase(text) { + return text.split().map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join(' '); + } }; From 8d1c5bd4a5e8bbb32ac5ea5664c7d85227730cd3 Mon Sep 17 00:00:00 2001 From: vzapo Date: Mon, 30 Dec 2019 15:23:07 +0000 Subject: [PATCH 2/4] bot proposed v1.1.0 --- commands/util/timenow.js | 58 +++++++++++++++++++++++++++++++++++++++ commands/util/timezone.js | 48 -------------------------------- index.js | 4 +-- package.json | 16 ++++++----- readme.md | 18 ++++++------ 5 files changed, 78 insertions(+), 66 deletions(-) create mode 100644 commands/util/timenow.js delete mode 100644 commands/util/timezone.js diff --git a/commands/util/timenow.js b/commands/util/timenow.js new file mode 100644 index 0000000..64bd887 --- /dev/null +++ b/commands/util/timenow.js @@ -0,0 +1,58 @@ +const Command = require('../../structures/Command'); +const moment = require('moment-timezone'); +const {firstUpperCase} = require('../../util/Utils.js'); +const cityTimezones = require('city-timezones'); + +module.exports = class TimeCommand extends Command { + constructor(client) { + super(client, { + name: 'timenow', + aliases: ['time-zone'], + group: 'util', + memberName: 'timenow', + description: 'Responds with the current time in a particular location. This can be done searching via timezone or city.', + examples: ['`!timenow New York`','`!timenow America/New_York`'], + credit: [ + { + name: 'List of tz database time zones', + url: 'https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' + }, + ], + args: [ + { + key: 'lookup', + label: 'time date', + prompt: 'Which time zone do you want to get the time of?', + type: 'string', + parse: lookup => lookup.toLowerCase() + } + ] + }); + } + + run(msg, {lookup}) { + let location = [], + country = '', + city = ''; + + const cityLookUp = cityTimezones.lookupViaCity(lookup); + + if (typeof cityLookUp[0] !== 'object' && !moment.tz.zone(lookup)) { + return msg.reply('Invalid time zone. For help please refer to .'); + } + let timeNow = !moment.tz.zone(lookup) ? moment().tz(cityLookUp[0].timezone).format('h:mm A z') : moment().tz(lookup).format('h:mm A z'); + + if(moment.tz.zone(lookup)){ + location = lookup.split('/'); + country = firstUpperCase(location[0]); + city = location[1] ? firstUpperCase(location[1]) : null; + city = city.split('_').join(' '); + } else { + country = cityLookUp[0].city; + city = cityLookUp[0].country; + } + + return msg.say(`The current time in ${country}, ${city} is ${timeNow}.`); + } + +}; \ No newline at end of file diff --git a/commands/util/timezone.js b/commands/util/timezone.js deleted file mode 100644 index 9531a93..0000000 --- a/commands/util/timezone.js +++ /dev/null @@ -1,48 +0,0 @@ -const Command = require('../../structures/Command'); -const moment = require('moment-timezone'); -const {firstUpperCase} = require('../../util/Utils.js'); -const cityTimezones = require('city-timezones'); - -module.exports = class TimeCommand extends Command { - constructor(client) { - super(client, { - name: 'timenow', - aliases: ['time-zone'], - group: 'util', - memberName: 'timenow', - description: 'Responds with the current time in a particular location.', - details: '**Zones:** ', - examples: ['`!timenow America/New_York`'], - credit: [ - { - name: 'List of tz database time zones', - url: 'https://en.wikipedia.org/wiki/List_of_tz_database_time_zones' - }, - ], - args: [ - { - key: 'timeDate', - label: 'time date', - prompt: 'Which time zone do you want to get the time of?', - type: 'string', - parse: timeDate => timeDate.replace(/ /g, '_').toLowerCase() - } - ] - }); - } - - run(msg, {timeDate }) { - - if (!moment.tz.zone(timeDate)) { - return msg.reply('Invalid time zone. Refer to .'); - } - - const time_now = moment().tz(timeDate).format('h:mm A'); - const time_zone = moment().tz(timeDate).zoneAbbr(); - const location = timeDate.split('/'); - - const place = firstUpperCase(location[0]); - const city = location[1] ? firstUpperCase(location[1]) : null; - return msg.say(`The current time in ${place}, ${city} is ${time_now} ${time_zone}.`); - } -}; \ No newline at end of file diff --git a/index.js b/index.js index 6e46ab9..c2edead 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,7 @@ client.once('ready', () => { getGameList(); }); -client.on('guildMemberAdd', member => member.setRoles(NEWS_ROLES).catch(logger.error)); +client.on('guildMemberAdd', member => member.setRoles(NEWS_ROLES).catch(err => {logger.error(err)})); client.on('disconnect', event => { logger.error(`[DISCONNECT] Disconnected with code ${event.code}.`); @@ -98,7 +98,7 @@ client.on('message', async (msg) => { await msg.react('2⃣'); } catch (error) { - logger.error('[ERROR] Failed to react with "RULE2".'); + logger.error({error,msg:'[ERROR] Failed to react with "RULE2".'}); } } }); diff --git a/package.json b/package.json index 6548bc1..7b2e117 100644 --- a/package.json +++ b/package.json @@ -5,24 +5,26 @@ "main": "index.js", "dependencies": { "cheerio": "^1.0.0-rc.3", + "city-timezones": "^1.2.0", "discord.js": "^11.5.1", - "discord.js-commando": "^0.9.0", - "dotenv": "^4.0.0", + "discord.js-commando": "^0.10.0", + "dotenv": "^8.2.0", "erlpack": "^0.1.3", "lunr": "^2.3.8", - "mathjs": "^5.10.3", + "mathjs": "^6.2.5", "merge": "^1.2.1", "moment": "^2.24.0", + "moment-timezone": "^0.5.27", "node-fetch": "^2.6.0", - "node-opus": "^0.2.9", + "node-opus": "^0.3.3", "node-superfetch": "^0.1.9", "pino": "^5.15.0", "redis": "^2.8.0", "request": "^2.88.0", "rss-parser": "^3.7.3", - "sqlite": "^2.9.3", - "steam-user": "^3.29.3", - "uws": "^8.14.1", + "sqlite": "^3.0.3", + "steam-user": "^4.12.4", + "uws": "^100.0.1", "youtube-search": "^1.1.4" }, "devDependencies": { diff --git a/readme.md b/readme.md index 46888e6..1dd4850 100644 --- a/readme.md +++ b/readme.md @@ -6,21 +6,21 @@ The code is written in JavaScript and is powered by [discord.js library](https:/ If you are used to those technologies and would like to contribute, PRs are welcome! -## Nerdy info +## Documentation / FAQ -### Requirements +### :memo: Requirements -node.js +- node.js -### Install - +### Install:wrench::hammer: +To install the project run thefollowing command: ``` $ npm i ``` -### Run +### Run :computer: Set the `.env` file properly and then: @@ -38,8 +38,8 @@ $ npm run dev ``` -### Inspiration - +### :books: Inspiration Many inspiration for RABot was obtained from the [Xiao bot's code](https://github.com/dragonfire535/xiao). - +*** +:information_source: For any issues please raise a [ticket](https://github.com/RetroAchievements/RABot/issues). From 765cc4dae37cace5daf353835ecaed16a9f851cf Mon Sep 17 00:00:00 2001 From: vzapo Date: Mon, 30 Dec 2019 15:30:50 +0000 Subject: [PATCH 3/4] 1.0.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 600edca..97b26f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "retroachievements-discord-bot", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7b2e117..f007160 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "retroachievements-discord-bot", - "version": "1.0.0", + "version": "1.0.1", "description": "https://github.com/hydrabolt/discord.js/", "main": "index.js", "dependencies": { From d7744ff124884ca19e141d46494775cc69ca39da Mon Sep 17 00:00:00 2001 From: vzapo Date: Mon, 30 Dec 2019 15:31:02 +0000 Subject: [PATCH 4/4] 1.1.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 97b26f2..07e6d40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "retroachievements-discord-bot", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f007160..7bd2a68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "retroachievements-discord-bot", - "version": "1.0.1", + "version": "1.1.0", "description": "https://github.com/hydrabolt/discord.js/", "main": "index.js", "dependencies": {