|
1 |
| -const Discord = require("discord.js"); |
2 |
| - |
3 |
| -const bot = new Discord.Client(); |
4 |
| - |
5 |
| -const config = require("./config.json"); |
6 |
| - |
7 |
| -const swears = require('./modules/swears/swears.js'); |
8 |
| - |
9 |
| -var unirest = require('unirest'); |
10 |
| - |
11 |
| -const current_year = new Date().getFullYear(); |
12 |
| - |
13 |
| -bot.on("ready", () => { |
14 |
| - console.log(`Botbot start with ${bot.users.size} users, in ${bot.channels.size} channels of ${bot.guilds.size} guilds.`); |
15 |
| - bot.user.setActivity(`do /help`); |
| 1 | +require('dotenv').config(); |
| 2 | + |
| 3 | +const { login, discord, sequelize } = require('./client'); |
| 4 | +const discordEvents = require('./discord'); |
| 5 | +const ticker = require('./ticker'); |
| 6 | +const jobs = require('./jobs'); |
| 7 | +const servers = require('./servers'); |
| 8 | +const models = require('./bags/models'); // Registers Models before initialising. |
| 9 | + |
| 10 | +console.log('Starting...'); |
| 11 | + |
| 12 | +sequelize.authenticate().then(() => { |
| 13 | + return sequelize.sync(); |
| 14 | +}).then(() => { |
| 15 | + return servers.fetch(); |
| 16 | +}).then(() => { |
| 17 | + return ticker.fetch(); |
| 18 | +}).then(() => { |
| 19 | + return login(); |
| 20 | +}).then(() => { |
| 21 | + return discordEvents.register(); |
| 22 | +}).then(() => { |
| 23 | + console.log('Ready!'); |
| 24 | + |
| 25 | + // Register any on-going Jobs. |
| 26 | + jobs.register(); |
| 27 | + |
| 28 | + // Updates all the Prices initially. |
| 29 | + ticker.update(); |
| 30 | +}).catch(e => { |
| 31 | + console.error(e); |
| 32 | + exit(); |
16 | 33 | });
|
17 | 34 |
|
18 |
| -bot.on("guildCreate", guild => { |
19 |
| - console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`); |
20 |
| - bot.user.setActivity(`do /help Serving ${bot.guilds.size} servers`); |
21 |
| -}); |
22 |
| - |
23 |
| -bot.on("guildDelete", guild => { |
24 |
| - console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`); |
25 |
| - bot.user.setActivity(`Serving ${bot.guilds.size} servers`); |
26 |
| -}); |
27 |
| - |
28 |
| -bot.on("message", async message => { |
29 |
| - |
30 |
| - if(message.author.bot) return; |
31 |
| - |
32 |
| - if(message.content.indexOf(config.prefix) !== 0) return; |
| 35 | +// Tell the process not to exit straight away. |
| 36 | +process.stdin.resume(); |
33 | 37 |
|
34 |
| - const args = message.content.slice(config.prefix.length).trim().split(/ +/g); |
35 |
| - const command = args.shift().toLowerCase(); |
36 |
| - //detect "fuck" || "shit" || "bitch" |
| 38 | +let killed = false; |
37 | 39 |
|
38 |
| - //use this function, checks if badWord is inside the system, if true, outputs stuffToSay |
39 |
| - function checkIfWords(badWord,stuffToSay) { |
40 |
| - if (command.toLowerCase().includes(badWord)) { |
41 |
| - //if command contains BadWord |
42 |
| - message.channel.send(stuffToSay); |
43 |
| - //send message to the channel stuffToSay |
44 |
| - return true; |
| 40 | +const exit = () => { |
| 41 | + if (killed) { |
| 42 | + return; |
45 | 43 | }
|
46 |
| - } |
47 |
| - |
48 |
| - //check all msg against a bad kid list list |
49 |
| - if (message.guild) { |
50 |
| - //format txt into readable format |
51 |
| - var string = message.content; |
52 |
| - var word = string.split(" "); |
53 |
| - var lower = string.toLowerCase(); |
54 |
| - //console.log(lower); |
55 |
| - //console.log(string); |
56 |
| - console.log("Author: " + message.author + "; Channel:" + message.channel + "; Message: " + message.content); |
57 |
| - //console.log(swears); |
58 |
| - //loop 1000 times |
59 |
| - for (i = 0; i < 2000; i++) { |
60 |
| - //checks through all values in the list. |
61 |
| - if (lower.indexOf(swears.list[i]) >= 0) |
62 |
| - { |
63 |
| - //If really bad word is true |
64 |
| - console.log(i); |
65 |
| - //remove message from channel |
66 |
| - message.delete(); |
67 |
| - //fansy dancy msg |
68 |
| - //message.channel.send("Hey! Your on santa's bad list now!"); |
69 |
| - break; |
70 |
| - } |
71 |
| - } |
72 |
| - } |
73 |
| - |
74 |
| - //the ".toLowerCase()" check all instances of the word, regardless of capitalization |
75 |
| -checkIfWords("fuck","HEY!!! WHY DO YOU THINK THAT **LANGUAGE** IS **APPROPRIATE** ON **THIS** SERVER HUH???!!!"); |
76 |
| -checkIfWords("shit",'**not cool**, you know better, buddy! Try, "Bowel Movement" instead.'); |
77 |
| -checkIfWords("bitch","Did you mean: *a female dog, wolf, fox, or otter?*"); |
78 |
| -checkIfWords("vape","#VapeNation!!! #GoGreen! https://www.youtube.com/watch?v=Dkm8Hteeh6M"); |
79 |
| -//checkIfWords("penis","Hey, no good word! bad!"); |
80 |
| -//checkIfWords("xxx","Hey, no good word! bad!"); |
81 |
| - |
82 |
| -//counseling seccession |
83 |
| -var sadArray = ["I'm sorry you're feeling sad. I'm here for you if you need anything.","If you want to talk, I'm a good listener!","Oh,no. It may not be much, but let me know if there is anything I can do for you.","I wish I had arms so I could give you a hug. But for now, maybe a joke or some music might help."] |
84 |
| -// if (checkIfWords("sad")) { |
85 |
| -// message.channel.send(sadArray[Math.floor(Math.random() * myArray.length)]); |
86 |
| -// } |
87 |
| - |
88 |
| -if (checkIfWords("sad") || checkIfWords("depression") || checkIfWords("depressed") || checkIfWords("upset") || checkIfWords("feel down") || checkIfWords("feeling down") || checkIfWords("under the weather")) { |
89 |
| - message.channel.send(sadArray[Math.floor(Math.random() * sadArray.length)]); |
90 |
| -} |
91 |
| - |
92 |
| -function suicideHotline() { |
93 |
| - message.channel.send("You're not alone. Confidential help is avaliable for free"); |
94 |
| - message.channel.send({embed: { |
95 |
| - color: 3447003, |
96 |
| - description: "National Suicide Hotline", |
97 |
| - author: { |
98 |
| - name: "National Suicide Hotline 24/7", |
99 |
| - icon_url: "https://static.logic0x.com/baseline-phone-24px.svg" |
100 |
| - }, |
101 |
| - fields: [ |
102 |
| - { |
103 |
| - name: "Need help? United States:", |
104 |
| - value: "## 1 (800) 273-8255" |
105 |
| - } |
106 |
| - ], |
107 |
| -}}); |
108 |
| -} |
109 |
| - |
110 |
| -if (checkIfWords("kill myself") || checkIfWords("hurt someone") || checkIfWords("suicide") || checkIfWords("killmyself") || checkIfWords("killme") || checkIfWords("don't want to live anymore") || checkIfWords("want to die now")) { |
111 |
| - suicideHotline(); |
112 |
| -} |
113 |
| - |
114 |
| -// Fun strings on invalid queries |
115 |
| -invalidQueryStrings = ["Nobody knows.", "It's a mystery.", "I have no idea.", "No clue, sorry!", "I'm afraid I can't let you do that.", "Maybe another time.", "Ask someone else.", "That is anybody's guess.", "Beats me.", "I haven't the faintest idea."] |
116 |
| - |
117 |
| -checkIfWords("bonzibuddy","Y(^o^)Y https://www.youtube.com/watch?v=MiRaRy4Qq8g Y(^o^)Y"); |
118 |
| - |
119 |
| - //sorry i type that it is against my religion but it is right sorry |
120 |
| - //commands |
121 |
| - |
122 |
| - var pickuplines = [ |
123 |
| - "I’m making a documentary on rare unique and exotic things on earth. Can we set up a lunch this afternoon to talk about you?", |
124 |
| - "Are you a pair of scissors? Because you look sharp ✂️", |
125 |
| - "Do you know CPR? Because I bet you take everyone's breath away", |
126 |
| - "You make my heart take flight✈️", |
127 |
| - "You know what's on the menu? Me-n-u 😘 ", |
128 |
| - "Are you a library book? Because I'm checking you out 📚", |
129 |
| - "According to search results, the moon has less gravity than Earth, But I'd still fall for you there."]; |
130 |
| - |
131 |
| - var flipacoin = ["You got heads!","You got tails!"] |
132 | 44 |
|
133 |
| - if(checkIfWords("<@462257314020327427>") || checkIfWords("!c") || checkIfWords("/c") || checkIfWords(".c") || checkIfWords("#c") || checkIfWords("*c") || checkIfWords("hey chloe") || checkIfWords("chloe")) |
134 |
| - { |
135 |
| - console.log("checking command: " + message.content); |
136 |
| - if (command === "<@460663266541043712>") { |
137 |
| - message.channel.send("Hi! How can I help?"); |
138 |
| - } |
| 45 | + jobs.kill(); |
139 | 46 |
|
140 |
| - if(checkIfWords("ping")) { |
141 |
| - const diff = (Date.now() - msg.createdTimestamp) / 1000; |
142 |
| - console.log("Pong! " + diff); |
143 |
| - message.channel.send("Pong! I heard you in" + diff + " seconds."); |
144 |
| - } |
145 |
| - |
146 |
| - if(checkIfWords("github")) { |
147 |
| - message.channel.send("Here is the link to the Github Repo: https://github.com/kylerchin/chloe"); |
148 |
| - } |
149 |
| - |
150 |
| - if (checkIfWords("invite")) { |
151 |
| - message.channel.send("https://discordapp.com/api/oauth2/authorize?client_id=462257314020327427&scope=bot&permissions=0") |
152 |
| - } |
153 |
| - |
154 |
| - if(command === "/vn") { |
155 |
| - message.channel.send("you wannna know huh huh? https://kawaiikitsunelover645.itch.io/sounds-of-the-night"); |
156 |
| - } |
157 |
| - |
158 |
| - if (checkIfWords("stockscreener")) { |
159 |
| - message.channel.send("https://www.tradingview.com/screener/") |
160 |
| - } |
161 |
| - |
162 |
| - if (checkIfWords("Flip a coin") || checkIfWords("flip")) { |
163 |
| - message.channel.send(flipacoin[Math.floor(Math.random() * flipacoin.length)]) |
164 |
| - } |
165 |
| - |
166 |
| - if(checkIfWords("pick") && checkIfWords("up") && checkIfWords("line")) { |
167 |
| - var random_pickupline = pickuplines[Math.floor(Math.random() * pickuplines.length)]; |
168 |
| - message.channel.send(random_pickupline); |
169 |
| - } |
170 |
| - |
171 |
| - //our product is quality that you can trust |
172 |
| - //request quote from api |
173 |
| - if (command === "/quote") { |
174 |
| - unirest.get("https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous").header("X-Mashape-Key", "gY8GQOVzJbmsh0SGQNT0yJoV2MLEp1ssXFLjsnFY9xdzBsenNr").header("Accept", "application/json") |
175 |
| - .end(function (result) { |
176 |
| - console.log(result.status, result.headers, result.body); |
177 |
| - message.channel.send(result.body[0]["quote"] + ' - ' + result.body[0]["author"]); |
178 |
| - //nice and pretty quote |
179 |
| - message.channel.send({embed: {color: 3447003,title: "Quote", |
180 |
| - fields: [{ |
181 |
| - name: "Quote:", |
182 |
| - value: result.body[0]["quote"] |
183 |
| - }, |
184 |
| - ], |
185 |
| - footer: { |
186 |
| - text: result.body[0]["author"] |
187 |
| - } |
188 |
| - } |
189 |
| - }); |
190 |
| - })} |
191 |
| - } |
192 |
| - |
193 |
| - if (checkIfWords("!c")) { |
194 |
| - if(checkIfWords("github")) { |
195 |
| - var githubMsg = "Here is the link to the Github Repo: https://github.com/kylerchin/chloe"; |
196 |
| - message.channel.send(githubMsg); |
197 |
| - } |
198 |
| - } |
199 |
| - |
200 |
| -//help |
201 |
| - if(command === "/help") { |
202 |
| - |
203 |
| - message.channel.send({embed: { |
204 |
| - color: 3447003, |
205 |
| - description: "*I Chloe and I'm here to help you!", |
206 |
| - author: { |
207 |
| - name: bot.user.username + "'s", |
208 |
| - icon_url: bot.user.avatarURL |
209 |
| - }, |
210 |
| - title: "Help!", |
211 |
| - fields: [{ |
212 |
| - name: "Prefixes:", |
213 |
| - value: "!c or .c or mention me!" |
214 |
| - }, |
215 |
| - { |
216 |
| - name: "ping", |
217 |
| - value: "I say Pong!" |
218 |
| - }, |
219 |
| - { |
220 |
| - name: "quote", |
221 |
| - value: "get a quality quote!" |
222 |
| - }, |
223 |
| - { |
224 |
| - name: "info", |
225 |
| - value: "make me explain myself" |
226 |
| - }, |
227 |
| - { |
228 |
| - name: "github", |
229 |
| - value: "get github repo link" |
230 |
| - }, |
231 |
| - { |
232 |
| - name: "invite", |
233 |
| - value: "invite more people to the party! :)" |
234 |
| - } |
235 |
| - ], |
236 |
| - footer: { |
237 |
| - icon_url: bot.user.avatarURL, |
238 |
| - text: "© 2018-" + current_year + " Weijing Wang" |
239 |
| - } |
240 |
| - } |
241 |
| -}); |
242 |
| - } |
243 |
| - |
244 |
| -}); |
| 47 | + killed = true; |
| 48 | + discord.destroy().then(() => { |
| 49 | + process.exit(); |
| 50 | + }); |
| 51 | +}; |
245 | 52 |
|
246 |
| -bot.login(config.token); |
| 53 | +// Register the Listeners for different exit events. |
| 54 | +process.on('exit', () => exit()); |
| 55 | +process.on('SIGINT', () => exit()); |
| 56 | +process.on('SIGUSR1', () => exit()); |
| 57 | +process.on('SIGUSR2', () => exit()); |
| 58 | +process.on('uncaughtException', () => exit()); |
0 commit comments