public async Task HandleVoicekickAdd(RawWebsocketMessage msg) { var req = VoicekickPacket.FromRaw(msg.rawMessage); var user = await Global.GetSwissbotUser(req.target); if (user == null) { await msg.Sender.SendAsync(InvalidTargetPacket.Compile(msg.rawMessage, $"Invalid target, {req.target} does not exist!"), System.Net.WebSockets.WebSocketMessageType.Text, true, CancellationToken.None); return; } var VoicekickUser = new VoiceKickUser(user, req.expires); CurrentVoiceKicked.Add(VoicekickUser); SaveVoiceKicked(); WebSocketServer.PushEvent("events.voicekick.user.add", VoicekickUser); // Add them to the channel override var vc = client.GetGuild(Global.SwissGuildId).GetVoiceChannel(627906629047943238); await vc.AddPermissionOverwriteAsync(user, new OverwritePermissions(connect : PermValue.Deny, viewChannel : PermValue.Allow)); await user.ModifyAsync(x => x.Channel = null); // Get the times var date = (new DateTime(1970, 1, 1)).AddMilliseconds(req.expires); var tm = date - DateTime.UtcNow; // DM them var channel = await user.GetOrCreateDMChannelAsync(); await channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Hey!", Description = "You have been blocked from joining event vc, this could be because you were ruining the game for other people or you were being a general nuisance.\n" + $"Dont worry tho, you will be able to join in {Math.Floor(tm.TotalMinutes)} minutes, {tm.Seconds} seconds", Color = Color.Red, Fields = new List <EmbedFieldBuilder>() { new EmbedFieldBuilder() { Name = "Expires:", Value = date.ToString("R") } } }.WithCurrentTimestamp().Build()); }
public async Task HandleVoicekickRevoke(RawWebsocketMessage msg) { VoicekickPacket req; try { req = VoicekickPacket.FromRaw(msg.rawMessage); } catch (Exception e) { return; } var user = CurrentVoiceKicked.FirstOrDefault(x => x.id == req.target.ToString()); if (user == null) { await msg.Sender.SendAsync(InvalidTargetPacket.Compile(msg.rawMessage, $"Invalid target, {req.target} does not exist!"), System.Net.WebSockets.WebSocketMessageType.Text, true, CancellationToken.None); return; } CurrentVoiceKicked.Remove(user); SaveVoiceKicked(); WebSocketServer.PushEvent("events.voicekick.user.remove", new { id = req.target.ToString() }); var vc = client.GetGuild(Global.SwissGuildId).GetVoiceChannel(627906629047943238); await vc.RemovePermissionOverwriteAsync(user.GetUser()); var channel = await user.GetUser().GetOrCreateDMChannelAsync(); await channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "You can now join event vc", Description = "Your voicekick has been revoked by an event manager, you are now able to join back!", Color = Color.Green }.WithCurrentTimestamp().Build()); }