-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyPetSeal-bot.js
199 lines (176 loc) · 5.87 KB
/
MyPetSeal-bot.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//#region imports
const config = require(`./config/config.json`);
const util = require(`@un-boxing-hosting/boxing-hosting-utils`)
const Discord = require(`discord.js`);
const REST = require('@discordjs/rest').REST;
const db = require('quick.db');
const utils = new util.Client();
const list = utils.getIDList();
const stafflist = utils.getStaffList();
//#endregion
//#region variables
const hostname = `https://mypetseal.com`
const dirname = `MyPetSeal/server`;
const intents = new Discord.IntentsBitField(config.intents);
const bot = new Discord.Client({
intents
});
//#endregion
//#region bot
bot.once(`ready`, async () => {
console.log(`Logged in as ${bot.user.tag}!`);
bot.user.setActivity(`MyPetSeal.com`, {
type: `WATCHING`
});
});
const commands = [
new Discord.SlashCommandBuilder().setName(`mypet`).setDescription(`See Your Pet From MyPetSeal.com`),
new Discord.SlashCommandBuilder().setName(`link`).setDescription(`How to link your account`),
new Discord.SlashCommandBuilder().setName(`help`).setDescription(`Help Command`),
new Discord.SlashCommandBuilder().setName(`pub-pets`).setDescription(`Public Pets`),
]
const rest = new REST({
version: '10'
}).setToken(config.token);
rest.put(
Discord.Routes.applicationCommands(config.botID), {
body: commands
},
);
bot.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const commandName = interaction.commandName;
console.log(interaction.user)
switch (commandName) {
case 'mypet':
var email = db.get(interaction.user.id)
if (email == undefined) {
interaction.reply(`You have not linked your account yet.`)
return;
}
var user = db.get(email).discord
var pets = db.get(email).pets
console.log(pets)
if (pets == undefined) {
interaction.reply(`You have no pets`)
}
// const file = new AttachmentBuilder(pets.img);
var petsEmbed = new Discord.EmbedBuilder()
.setTitle(`Your pets`)
.setURL(hostname)
//.setDescription(`${pets}`)
.addFields({
name: `Name`,
value: `${pets.name}`
}, {
name: `Happyness`,
value: `${pets.happy}`
}, {
name: `Owner`,
value: `${user.name}`
})
.setImage(pets.img)
.setColor(` #0099ff`)
.setFooter({
text: 'made by un boxing hosting',
iconURL: 'https://bots.unboxingman.com/pix/logo.png'
})
.setTimestamp()
interaction.reply({
embeds: [petsEmbed]
})
break;
case 'link':
interaction.reply(`To link your account, go to ${hostname}/login and login with discord (the email MUST match both accounts).`)
break;
case 'help':
interaction.reply(`To see your pets, use the command \`Mypet\`.\nTo link your account, use the command \`Link\`.`)
break;
case 'pub-pets':
var public_pets = await pubpets()
var embeds = []
console.log(public_pets)
var petsEmbed = new Discord.EmbedBuilder()
public_pets.forEach(pet => {
petsEmbed.setTitle(`public pets`)
petsEmbed.setURL(hostname)
// .setDescription(`${pet.owner}`)
petsEmbed.addFields({
name: `Name`,
value: pet.pets.name
}, {
name: `Happness`,
value: `${pet.pets.happy}`
}, {
name: `Owner`,
value: `${pet.owner}`
})
petsEmbed.setImage(pet.pets.img)
})
petsEmbed.setColor(` #0099ff`)
petsEmbed.setFooter({
text: 'made by un boxing hosting',
iconURL: 'https://bots.unboxingman.com/pix/logo.png'
})
petsEmbed.setTimestamp()
interaction.reply({
embeds: [petsEmbed]
})
break;
}
})
bot.on(`messageCreate`, async (message) => {
console.log(`${message.author.username} said: ${message.content}`);
const idlist = await list;
const staffIDlist = await stafflist;
if (message.author.bot) return;
const prefix = config.prefix;
if (!message.content.startsWith(prefix)) return;
const args2 = message.content.slice(prefix.length).split(/ +/);
const args = message.content.split(/\s+/g);
const command = args.shift().slice(prefix.length).toLowerCase();
console.log(command)
switch (command) {
case `mypet`:
}
})
bot.login(config.token);
//# endregion
//#region functions
async function pubpets() {
var public = db.get(`public_pets`)
var public_pets = []
await public.forEach(email => {
var user = db.get(email)
var owner = getName(user)
if (user.pets != undefined) {
public_pets.push({
owner: owner.name,
pets: user.pets
})
}
})
console.log(public_pets)
return public_pets
}
function getName(user) {
if (user.discord !== undefined && user.discord !== null) {
var send = {
email: user.discord.email,
name: user.discord.name,
id: user.discord.id
}
return send;
}
if (user.google != undefined && user.google != null) {
var send = {
email: user.google.email,
name: user.google.name,
id: user.google.id
}
return send;
}
}
module.exports = {
bot,
}