Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bot to v1.1.0 #38

Merged
merged 4 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions commands/util/timenow.js
Original file line number Diff line number Diff line change
@@ -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 <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>.');
}
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}.`);
}

};
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`);
Expand All @@ -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;
Expand Down Expand Up @@ -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".'});
}
}
});
Expand Down Expand Up @@ -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);
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
{
"name": "retroachievements-discord-bot",
"version": "1.0.0",
"version": "1.1.0",
"description": "https://github.com/hydrabolt/discord.js/",
"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": {
Expand Down
18 changes: 9 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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).
4 changes: 4 additions & 0 deletions util/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
}
};