-
Notifications
You must be signed in to change notification settings - Fork 0
/
TvRoom.cs
80 lines (75 loc) · 2.37 KB
/
TvRoom.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Discord;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GlacierByte.Discord.Plugin
{
internal class TvRoom
{
private readonly SocketUser Owner;
public readonly IVoiceChannel Channel;
private readonly Dictionary<ulong, SocketUser> Waiting;
private readonly Dictionary<ulong, SocketUser> Allowed;
private readonly DateTime Started;
public TvRoom(SocketUser owner, IVoiceChannel channel)
{
Owner = owner;
Channel = channel;
Waiting = new Dictionary<ulong, SocketUser>();
Allowed = new Dictionary<ulong, SocketUser>();
Started = DateTime.Now;
}
public async Task RemoveRoom()
{
await Channel.DeleteAsync();
}
public async Task NewUser(SocketUser newUser)
{
if (newUser.Id == Owner.Id || (Allowed.ContainsKey(newUser.Id)))
{
return;
} else if (DateTime.Now.Subtract(Started).TotalSeconds < 30)
{
await AllowUser(newUser);
} else
{
await NotAllowUser(newUser);
}
}
private async Task NotAllowUser(SocketUser newUser)
{
if (Allowed.ContainsKey(newUser.Id))
{
Allowed.Remove(newUser.Id);
}
if (!Waiting.ContainsKey(newUser.Id))
{
Waiting.Add(newUser.Id, newUser);
}
await (newUser as IGuildUser)?.ModifyAsync(x =>
{
x.Mute = true;
});
}
private Task AllowUser(SocketUser newUser)
{
if (Waiting.ContainsKey(newUser.Id))
{
Waiting.Remove(newUser.Id);
}
Allowed.TryAdd(newUser.Id, newUser);
return Task.CompletedTask;
}
public async Task UpdateUser(SocketUser socketUser)
{
if(Waiting.ContainsKey(socketUser.Id) && !(socketUser as SocketGuildUser)?.IsMuted == true)
{
await AllowUser(socketUser);
} else if (Allowed.ContainsKey(socketUser.Id) && (socketUser as SocketGuildUser)?.IsMuted == true)
{
await NotAllowUser(socketUser);
}
}
}
}