-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuildEveryoneRole.cs
55 lines (52 loc) · 1.88 KB
/
GuildEveryoneRole.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.WebSocket;
using FreneticUtilities.FreneticDataSyntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FreneticDiscordBot;
public class GuildEveryoneRole
{
public Dictionary<ulong, ulong> GuildToEveryoneRole = [];
public void Init(FDSSection section, DiscordSocketClient client)
{
foreach (string key in section.GetRootKeys())
{
GuildToEveryoneRole[ulong.Parse(key)] = section.GetUlong(key).Value;
}
client.UserJoined += async (user) =>
{
if (GuildToEveryoneRole.TryGetValue(user.Guild.Id, out ulong everyoneRole))
{
Console.WriteLine($"[Guild Everyone Role] User joined, adding everyone role: {user.Id}");
await user.AddRoleAsync(everyoneRole);
}
};
client.Ready += async () =>
{
try
{
foreach ((ulong guild, ulong role) in GuildToEveryoneRole)
{
SocketGuild g = client.GetGuild(guild);
await g.DownloadUsersAsync();
Console.WriteLine($"[Guild Everyone Role] checking {g.Users.Count} users...");
foreach (SocketGuildUser user in g.Users)
{
if (!user.Roles.Any(r => r.Id == role))
{
Console.WriteLine($"[Guild Everyone Role] adding role to user: {user.Id}");
await user.AddRoleAsync(g.GetRole(role));
}
}
Console.WriteLine($"[Guild Everyone Role] complete.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Role bouncer Ready error: {ex}");
}
};
}
}