1 |
|
/** |
2 |
|
* This file is part of SudoBot. |
3 |
|
* |
4 |
|
* Copyright (C) 2021-2022 OSN Inc. |
5 |
|
* |
6 |
|
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
|
* under the terms of the GNU Affero General Public License as published by |
8 |
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* SudoBot is distributed in the hope that it will be useful, but |
12 |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU Affero General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU Affero General Public License |
17 |
|
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
|
*/ |
19 |
|
|
20 |
import { GuildChannel, PermissionString, Role, RoleResolvable, User } from "discord.js"; |
import { GuildChannel, PermissionString, Role, RoleResolvable, User } from "discord.js"; |
21 |
import MessageEmbed from "../client/MessageEmbed"; |
import MessageEmbed from "../client/MessageEmbed"; |
22 |
import ChannelLock from "../models/ChannelLock"; |
import ChannelLock from "../models/ChannelLock"; |
63 |
channel_id: channel.id, |
channel_id: channel.id, |
64 |
reason, |
reason, |
65 |
previous_perms: permJson, |
previous_perms: permJson, |
66 |
role_id: lockRole.id |
role_id: lockRole.id, |
67 |
|
createdAt: new Date() |
68 |
}); |
}); |
69 |
|
|
70 |
await channel.permissionOverwrites.edit(lockRole, { |
await channel.permissionOverwrites.edit(lockRole, { |
102 |
const lockRole = role ? (role instanceof Role ? role : (await channel.guild.roles.fetch(role))!) : channel.guild.roles.everyone; |
const lockRole = role ? (role instanceof Role ? role : (await channel.guild.roles.fetch(role))!) : channel.guild.roles.everyone; |
103 |
|
|
104 |
const channelLock = await ChannelLock.findOne({ |
const channelLock = await ChannelLock.findOne({ |
105 |
where: { |
channel_id: channel.id, |
106 |
channel_id: channel.id, |
guild_id: channel.guild.id, |
107 |
guild_id: channel.guild.id, |
role_id: lockRole.id |
|
role_id: lockRole.id |
|
|
} |
|
108 |
}); |
}); |
109 |
|
|
110 |
if (!channelLock) { |
if (!channelLock) { |
112 |
return false; |
return false; |
113 |
} |
} |
114 |
|
|
115 |
const permissions = channelLock?.get('previous_perms') as { allow: PermissionString[] | null, deny: PermissionString[] | null }; |
const permissions = channelLock?.previous_perms; // as { allow: PermissionString[] | null, deny: PermissionString[] | null } |
116 |
|
|
117 |
if (!permissions && !force) { |
if (!permissions && !force) { |
118 |
console.log('Permission error'); |
console.log('Permission error'); |
120 |
} |
} |
121 |
|
|
122 |
const transform = (key: PermissionString) => { |
const transform = (key: PermissionString) => { |
123 |
if (!permissions.allow || !permissions.deny) { |
if (!permissions?.allow || !permissions?.deny) { |
124 |
return undefined; |
return undefined; |
125 |
} |
} |
126 |
|
|
139 |
} |
} |
140 |
}; |
}; |
141 |
|
|
142 |
if (!permissions.allow && !permissions.deny) { |
if (!permissions?.allow && !permissions?.deny) { |
143 |
await channel.permissionOverwrites.delete(lockRole); |
await channel.permissionOverwrites.delete(lockRole); |
144 |
} |
} |
145 |
else { |
else { |
151 |
}, { reason }); |
}, { reason }); |
152 |
} |
} |
153 |
|
|
154 |
await channelLock?.destroy(); |
await channelLock?.delete(); |
155 |
|
|
156 |
if (sendConfirmation && channel.isText()) { |
if (sendConfirmation && channel.isText()) { |
157 |
await channel.send({ |
await channel.send({ |