forked from ChrisChrome/weather-bot
Add perm check to subscribe command
This commit is contained in:
parent
e952ec60e7
commit
4bb679cef8
25
index.js
25
index.js
|
@ -832,21 +832,26 @@ discord.on("interactionCreate", async (interaction) => {
|
|||
filterEvt = interaction.options.getString("filterevt") || null;
|
||||
message = interaction.options.getString("message") || null;
|
||||
if (interaction.inGuild()) {
|
||||
db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
||||
} else if (row) {
|
||||
return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true });
|
||||
}
|
||||
db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => {
|
||||
interaction.channel.send("Permission check").then((msg) => {
|
||||
msg.delete();
|
||||
db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true });
|
||||
} else if (row) {
|
||||
return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true });
|
||||
}
|
||||
db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
}).catch((err) => {
|
||||
interaction.reply({ content: "Failed to subscribe to room. Bot does not have send message permissions here!", ephemeral: true });
|
||||
});
|
||||
} else { // We're in a DM
|
||||
db.get(`SELECT * FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [interaction.user.id, room], (err, row) => {
|
||||
|
|
Loading…
Reference in a new issue