-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet.cs
55 lines (50 loc) · 1.66 KB
/
Set.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
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace bot.Handlers
{
public class Set : ModuleBase<SocketCommandContext>
{
[Command("set")]
public async Task SetAsync(params SocketRole[] roles)
{
await Context.Message.DeleteAsync();
if (!Context.Message.Channel.Id.Equals(Global.SetupId))
{
var msg = await Context.Channel.SendMessageAsync
("You can use `!set` command only in `setup` channel");
await Task.Delay(5000);
await Context.Channel.DeleteMessageAsync(msg);
return;
}
var user = Context.Guild.GetUser(Context.Message.Author.Id);
var assignedRoles = user.Roles;
foreach (var role in assignedRoles)
{
if (role.Id == Global.EveryoneId) continue;
await user.RemoveRoleAsync(role);
}
if (roles.Length == 0)
{
var guildRoles = Context.Guild.Roles;
foreach (var role in guildRoles)
{
if (Global.ValidRoles.Contains(role.Name))
{
await user.AddRoleAsync(role);
}
}
return;
}
foreach (var role in roles)
{
await user.AddRoleAsync(role);
}
}
}
}