-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
146 lines (118 loc) · 3.61 KB
/
index.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const mongoose = require('mongoose');
const userData = require('./userData');
const Discord = require('discord.js');
const axios = require('axios');
require('dotenv').config();
const token = process.env.TOKEN;
const key = process.env.KEY;
const pass = process.env.PASS;
const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES"]
});
//command prefix
const prefix = '';
//file reading
const fs = require('fs');
const testSchema = require('./userData');
const { db } = require('./userData');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
//bus lines map
const busLines = new Map([
["bb", 'BB'],
["nw", 'NW'],
["cn", 'CN'],
["cs", 'CS'],
['csx', 'CSX'],
['mx', 'MX'],
['ne', "NE"],
['ws', "WS"],
['wx', 'WX']
]);
//common stops map
const busStopIds = new Map([
//Commuter North (northbound)
["crislercenter", "S001"],
["transportationgate", "S003"],
["facilitiesservices", "S004"],
["greene/hoover", "S006"],
["intramuralbuildingout", "S007"],
["cctcchem", "C250"],
["couzenshall", "M305"],
["markleyhall", "M313"],
["taubmanout", "M315"],
["cancercenterout", "M319"],
["fullerroard", "M350"],
["artarchitecture", "N552"],
["cooleylabin", "N404"],
["fxbout", "N406"],
["fordbuilding", "N432"],
["huronhubbardout", "N434"],
//Northwood
["cctcmuseum", "C251"],
["hubbardin", "N433"],
["bursleyin", "N407"],
["bursleyout", "N408"]
]);
//timerids
intervals = new Map();
//ready check
client.on('ready', async () => {
console.log('KirbyBus GOOD');
await mongoose.connect(pass || '', {
keepAlive: true,
})
});
//message comands
client.on('message', async message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
//takes first message and splits into array
const args = message.content.slice(prefix.length).split(/ +/);
//accounts for capital letters in command
const command = args.shift().toLowerCase();
//get home location
if (command === 'gethome') {
client.commands.get('gethome').execute(message);
}
//set home location
if(command === 'sethome') {
client.commands.get('sethome').execute(message, args, busStopIds);
}
//get selected bus
if (command === 'getbus') {
client.commands.get('getbus').execute(message);
}
//set selected bus
if(command === 'setbus') {
client.commands.get('setbus').execute(message, args, busLines);
}
//specific bus line commands
if(command === 'bus') {
client.commands.get('bus').execute(message, args, busStopIds, busLines);
}
//start reminders
if(command === 'startremind') {
//check bus time every 10 seconds
intervals.set(message.author.id, setInterval(function() {client.commands.get('reminder').execute(message, busStopIds, busLines) }, 10000));
}
//stop reminders
if(command === 'stopremind') {
clearInterval(intervals.get(message.author.id));
}
//test command for mongodb
// if (command === "lolgoon") {
// message.channel.send(`yo you ${message.author.id}`);
// setTimeout(async () => {
// await userData.findOneAndUpdate(
// {_id: 'goonsa'} ,
// {$set: {busData: 'bosing'}},
// {upsert: true}
// ).exec()}, 1000);
// }
}
)
client.login(token);