summaryrefslogtreecommitdiff
path: root/discord.js
blob: cb6f7d985c2024d064891abcd8d5cf9148945c7e (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function startDiscord() {
    try {
        const { Client, GatewayIntentBits } = require('discord.js');
        const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

        client.on('ready', () => {
            console.log(`Logged in as ${client.user.tag}!`);
        });

        function send(channel, text) {
            channel.send({
                embeds: [
                    {
                        description: text
                    }
                ]
            })
        }

        client.on('messageCreate', (msg) => {
            if (!msg.guild || msg.author.bot) return;

            let message = msg.content;

            if (message.startsWith(".") && !message.startsWith("..") && message.trim() !== "." && message.trim() !== ".c.") {
                let command;

                try {
                    command = message.replaceAll(/ +/g, " ");
                    if (command.startsWith(". ")) command = "." + command.substring(2);
                    command = command.split(" ")[0].substring(1).replaceAll("/", "-");
                    let parameter = message.split(" ").splice(1).join(" ");

                    require('./handler')({
                        command,
                        parameter,
                        source: "discord",
                        message: msg,
                        channel: msg.channel,
                        client,
                        discordSend: send
                    });
                } catch (e) {
                    send(msg.channel, "❓ Hmm, something isn't quite right! I was trying to process your message and something wrong happened. I think you need to report this so it can be fixed!\n\n```plaintext\n" + e.stack + "\n```");
                }
            } else if (message.includes("<@" + client.user.id + ">")) {
                send(msg.channel, "👋 Hello! I think you forgot my prefix is `.`, use `.help` to get help.");
            } else {
                if (!lastMessages[msg.channel.id]) lastMessages[msg.channel.id] = [];
                lastMessages[msg.channel.id].unshift(message);
                lastMessages[msg.channel.id] = lastMessages[msg.channel.id].splice(0, 5);

                let text = msg.content.toLowerCase().trim();

                if (message.author.id === "186730180872634368" || message.author.id === "189069518016872448" || message.author.id === "493845599469174794") {
                    let worth = 1 / (score['score'] / 100);
                    if (worth < 0.1) worth = 0.1;
                    if (worth > 100) worth = 100;

                    if (score['score'] === 0) {
                        score['score'] = 0.01;
                    }

                    if (text.includes("....")) {
                        score['score'] -= text.replace(/[^.]/gm, "").length * worth;
                    }

                    if (text.replace(/[^.]/gm, "").length === text.length) {
                        score['score'] -= text.replace(/[^.]/gm, "").length * 5 * worth;
                    }

                    if (text.includes(".c.")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("neigh")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("-c-")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("bye")) {
                        score['score'] -= 50 * worth;
                    }

                    if (text.endsWith(".") && !text.endsWith("..") && !text.endsWith("...")) {
                        score['score'] -= 10 * worth;
                    }

                    if (text.match(/^\*(.*)\*$/gm)) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("❤")) {
                        score['score'] += text.replace(/[^❤]/gm, "").length * 3 * worth;
                    }

                    if (text.includes("hehe")) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("pff")) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("mhm!")) {
                        score['score'] += 1 * worth;
                    }

                    if (text.includes("cutie")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("silly")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("sweetie")) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("sis")) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("nini")) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("good night")) {
                        score['score'] += 2 * worth;
                    }

                    if (text.includes("hehehehe")) {
                        score['score'] += 4 * worth;
                    }

                    if (text.includes("hehehe")) {
                        score['score'] += 3 * worth;
                    }

                    if (text.includes("woo!")) {
                        score['score'] += 3 * worth;
                    }

                    if (text.includes("yay!")) {
                        score['score'] += 3 * worth;
                    }

                    if (text.includes("/s")) {
                        score['score'] += 3 * worth;
                    }

                    if (text.includes("love you")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("love u")) {
                        score['score'] += 5 * worth;
                    }

                    if (text.includes("^c^")) {
                        score['score'] += 3 * worth;
                    }

                    if (Math.floor(score['percentage']) < Math.floor(score['score'] / 12.5)) {
                        send(msg.channel, "🎉 Congrats! Your love score is now at " + Math.floor(score['score'] / 12.5) + "%, keep it up!");
                    }

                    score['percentage'] = score['score'] / 12.5;
                }
            }
        });

        client.login(require('./credentials.json').discord);
    } catch (e) {
        setTimeout(() => {
            startDiscord();
        }, 300000);
    }
}

startDiscord();