-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequireBotPermissionsAttribute.cs
55 lines (45 loc) · 2.44 KB
/
RequireBotPermissionsAttribute.cs
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
/* unified/ban - Management and protection systems
© fabricators SRL, https://fabricators.ltd , https://unifiedban.solutions
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License with our addition
to Section 7 as published in unified/ban's the GitHub repository.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License and the
additional terms along with this program.
If not, see <https://docs.fabricators.ltd/docs/licenses/unifiedban>.
For more information, see Licensing FAQ:
https://docs.fabricators.ltd/docs/licenses/faq */
using System;
using System.Collections.Generic;
namespace Unifiedban.Next.Common.Telegram
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class RequireBotPermissionsAttribute : CheckPermissionBaseAttribute
{
public Enums.TelegramPermissions Permission;
public RequireBotPermissionsAttribute(Enums.TelegramPermissions permission)
{
Permission = permission;
}
public override bool ExecuteCheck(UserPrivileges userPrivileges)
{
return Permission switch
{
Enums.TelegramPermissions.CanManageChat => userPrivileges.CanManageChat,
Enums.TelegramPermissions.CanPostMessages => userPrivileges.CanPostMessages,
Enums.TelegramPermissions.CanEditMessages => userPrivileges.CanEditMessages,
Enums.TelegramPermissions.CanDeleteMessages => userPrivileges.CanDeleteMessages,
Enums.TelegramPermissions.CanManageVoiceChats => userPrivileges.CanManageVoiceChats,
Enums.TelegramPermissions.CanRestrictMembers => userPrivileges.CanRestrictMembers,
Enums.TelegramPermissions.CanPromoteMembers => userPrivileges.CanPromoteMembers,
Enums.TelegramPermissions.CanChangeInfo => userPrivileges.CanChangeInfo,
Enums.TelegramPermissions.CanInviteUsers => userPrivileges.CanInviteUsers,
Enums.TelegramPermissions.CanPinMessages => userPrivileges.CanPinMessages,
_ => false
};
}
}
}