This repository has been archived by the owner on Feb 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.ts
executable file
·58 lines (46 loc) · 1.96 KB
/
bot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {format} from 'date-fns';
import {database} from 'firebase-admin';
import {BotToken} from './config/config';
import {Client, GuildMember, Message} from 'discord.js';
export default class Bot {
constructor(private client: Client, private firebase: database.Database) {
this.registerListeners();
this.client.login(BotToken);
}
private registerListeners = () => {
this.client.on('ready', this.onReady);
this.client.on('guildMemberAdd', this.onMemberAdded);
this.client.on('message', this.processMessage);
}
private onReady = async (): Promise<void> => {
console.log('Aura has started! All systems green.');
}
private onMemberAdded = async (member: GuildMember): Promise<void> => {
let snapshot: database.DataSnapshot = await this.firebase.ref(`discord/${member.id}`).once('value');
if (!snapshot.exists()) {
// find the role we are looking for on the server the user just joined
let guest = member.guild.roles.find(role => role.name == 'Guest');
// set the users roles to just that role (Note, this removes all other roles)
await member.setRoles([guest]);
console.log(`Welcome to ${member.nickname}`);
}
}
private processMessage = async (message: Message) => {
if (message.author.bot) return;
if (message.content.indexOf('!') !== 0) return;
const args = message.content.slice(1).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === 'time') {
const date = new Date(Date.now());
const utc = new Date(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds()
);
message.channel.send(format(utc, 'dddd, DD MMM, YYYY HH:mm:ss'));
}
}
}