public async Task Mute([Summary("The user to mute")] SocketGuildUser user, [Summary("Number of minutes to mute for")] int minutes = 5, [Summary("The reason for muting")][Remainder] string reason = null) { await Context.Channel.TriggerTypingAsync(); if (user.Hierarchy > Context.Guild.CurrentUser.Hierarchy) { await Context.Channel.SendEmbedAsync("Invalid User", "That user has a higher position than the bot!", await _servers.GetEmbedColor(Context.Guild.Id), ImageLookupUtility.GetImageUrl("ERROR_IMAGES")); return; } // Check for muted role, attempt to create it if it doesn't exist var role = (Context.Guild as IGuild).Roles.FirstOrDefault(x => x.Name == "Muted"); if (role == null) { role = await Context.Guild.CreateRoleAsync("Muted", new GuildPermissions(sendMessages : false), null, false, null); } if (role.Position > Context.Guild.CurrentUser.Hierarchy) { await Context.Channel.SendEmbedAsync("Invalid permissions", "the muted role has a higher position than the bot!", await _servers.GetEmbedColor(Context.Guild.Id), ImageLookupUtility.GetImageUrl("ERROR_IMAGES")); return; } if (user.Roles.Contains(role)) { await Context.Channel.SendEmbedAsync("Already Muted", "That user is already muted!", await _servers.GetEmbedColor(Context.Guild.Id), ImageLookupUtility.GetImageUrl("ERROR_IMAGES")); return; } await role.ModifyAsync(x => x.Position = Context.Guild.CurrentUser.Hierarchy); foreach (var channel in Context.Guild.Channels) { if (!channel.GetPermissionOverwrite(role).HasValue || channel.GetPermissionOverwrite(role).Value.SendMessages == PermValue.Allow) { await channel.AddPermissionOverwriteAsync(role, new OverwritePermissions(sendMessages : PermValue.Deny)); } } MuteHandler.AddMute(new Mute { Guild = Context.Guild, User = user, End = DateTime.Now + TimeSpan.FromMinutes(minutes), Role = role }); await user.AddRoleAsync(role); await Context.Channel.SendEmbedAsync($"Muted {user.Username}", $"Duration: {minutes} minutes\nReason: {reason ?? "None"}", await _servers.GetEmbedColor(Context.Guild.Id), ImageLookupUtility.GetImageUrl("MUTE_IMAGES")); await _servers.SendLogsAsync(Context.Guild, "Muted", $"{Context.User.Mention} muted {user.Mention}"); _logger.LogInformation("{user} muted {target} in {server}", Context.User.Username, user.Username, Context.Guild.Name); }
internal static void OnVerified(VerifiedEventArgs ev) { Player dPlayer = ev.Player.GetPlayer() ?? new Collections.Player( ev.Player.RawUserId, ev.Player.AuthenticationType.ToString().ToLower(), ev.Player.Nickname ); PlayerData.Add(ev.Player, dPlayer); if (dPlayer.Name != ev.Player.Nickname) { dPlayer.Name = ev.Player.Nickname; dPlayer.Save(); } if (!dPlayer.IsMuted() && MuteHandler.QueryPersistentMute($"{dPlayer.Id}@{dPlayer.Authentication}")) { MuteHandler.RevokePersistentMute($"{dPlayer.Id}@{dPlayer.Authentication}"); } if (!WatchListCollection.Exists(p => p.Target == ev.Player.GetPlayer())) { return; } foreach (Exiled.API.Features.Player staffer in Exiled.API.Features.Player.List.Where(ply => ply.RemoteAdminAccess)) { staffer.Broadcast(Plugin.Singleton.Config.Translation.WatchlistStaffersBroadcastJoin.Duration, Plugin.Singleton.Config.Translation.WatchlistStaffersBroadcastJoin.Content.Replace("{player}", $"{ev.Player.Nickname} ({ev.Player.UserId})").Replace("{reason}", WatchListCollection.Find(ply => ply.Target == ev.Player.GetPlayer()).Last().Reason), global::Broadcast.BroadcastFlags.Normal, true); } if (dPlayer.IsBanned()) { ev.Player?.Disconnect(Plugin.Singleton.Config.Translation.BanTranslation.PlayerBanMessage.Replace("{reason}", BanCollection.Find(b => b.Target == dPlayer).Last().Reason)); } }
private static bool Prefix(CharacterClassManager __instance, bool value) { try { ChangingMuteStatusEventArgs ev = new ChangingMuteStatusEventArgs(API.Features.Player.Get(__instance._hub), value, true); Player.OnChangingMuteStatus(ev); if (!ev.IsAllowed) { if (value == true) { MuteHandler.RevokePersistentMute(__instance.UserId); } else { MuteHandler.IssuePersistentMute(__instance.UserId); } return(false); } return(true); } catch (Exception e) { Exiled.API.Features.Log.Error($"{typeof(ChangingMuteStatus).FullName}.{nameof(Prefix)}:\n{e}"); return(true); } }
public void OnPlayerJoin(PlayerJoinEvent ev) { if (MuteHandler.QueryPersistantMute(ev.Player.SteamId)) { (ev.Player.GetGameObject() as UnityEngine.GameObject).GetComponent <CharacterClassManager>().NetworkMuted = true; } Timing.RunCoroutine(this._DelayedForceSyncMute(), Segment.FixedUpdate); }
public CommandHandler(DiscordSocketClient client, CommandService commands, ISettings settings, IServiceProvider serviceProvider, ILogger <CommandHandler> logger, IServerService servers, BannerImageService bannerImageService, IAutoRoleService autoRoleService, IProfanityRepository profanityRepository, IApiService apiService, IWelcomeMessageRepository welcomeMessageRepository, IPartMessageRepository partMessageRepository, IUserRepository userRepository, IInviteRepository inviteRepository, IServerInviteRepository serverInviteRepository, IServerRepository serverRepository) { _client = client; _commands = commands; _settings = settings; _serviceProvider = serviceProvider; _logger = logger; _servers = servers; _bannerImageService = bannerImageService; _autoRoleService = autoRoleService; _profanityRepository = profanityRepository; _apiService = apiService; _welcomeMessageRepository = welcomeMessageRepository; _partMessageRepository = partMessageRepository; _userRepository = userRepository; _inviteRepository = inviteRepository; _serverInviteRepository = serverInviteRepository; _serverRepository = serverRepository; _client.MessageReceived += OnMessageReceived; _client.UserJoined += OnUserJoined; _client.ReactionAdded += OnReactionAdded; _client.MessageUpdated += OnMessageUpated; _client.UserLeft += OnUserLeft; _client.JoinedGuild += OnJoinedGuild; _client.Ready += OnReady; _client.InviteCreated += OnInviteCreated; _commands.CommandExecuted += OnCommandExecuted; ProfanityHelper.ProfanityRepository = profanityRepository; Task.Run(async() => await MuteHandler.MuteWorker(client)); Task.Run(async() => await PomodoroHandler.PomodoroWorker(client)); }
/// <summary> /// Apply a punish to the specified <see cref="Player"/>. /// </summary> /// <param name="target">The <see cref="Exiled.API.Features.Player"/> player.</param> /// <param name="issuer">The <see cref="Collections.Player"/> staffer.</param> /// <param name="dPlayer">The <see cref="Collections.Player"/> player.</param> /// <param name="punishType">The <see cref="Enums.PunishType"/> punish.</param> /// <param name="reason">The reason of the punish.</param> /// <param name="duration">The <see cref="DateTime"/> duration.</param> public static void ApplyPunish(Player target, Collections.Player issuer, Collections.Player dPlayer, PunishType punishType, string reason, string duration) { switch (punishType) { case PunishType.Warn: Warn warn = new Warn(dPlayer, issuer, reason, DateTime.Now, WarnCollection.Find(w => w.Target.Id == dPlayer.Id).Count(), Server.Port, false); warn.Save(); target?.Broadcast(Plugin.Singleton.Config.Translation.WarnTranslation.PlayerWarnedMessage.Duration, Plugin.Singleton.Config.Translation.WarnTranslation.PlayerWarnedMessage.Content.Replace( "{reason}", reason), global::Broadcast.BroadcastFlags.Normal, true); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(warn), dPlayer, ActionType.Add); break; case PunishType.Mute: Mute mute = new Mute(dPlayer, issuer, reason, GetDate(duration), DateTime.Now, DateTime.Now.AddSeconds(GetTotalSeconds(duration).TotalSeconds), MuteCollection.Find(m => m.Target == dPlayer).Count(), Server.Port, false); mute.Save(); MuteHandler.IssuePersistentMute(dPlayer.Id + dPlayer.Authentication); target?.Broadcast(Plugin.Singleton.Config.Translation.MuteTranslation.PlayerMuteMessage.Duration, Plugin.Singleton.Config.Translation.WarnTranslation.PlayerWarnedMessage.Content .Replace("{duration}", GetDate(duration)).Replace("{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(mute), dPlayer, ActionType.Add); break; case PunishType.Kick: Kick kick = new Kick(dPlayer, issuer, reason, DateTime.Now, KickCollection.Find(x => x.Target.Id == dPlayer.Id).Count(), Server.Port, false); kick.Save(); target?.Kick(Plugin.Singleton.Config.Translation.KickTranslation.PlayerKickedMessage.Replace("{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(kick), dPlayer, ActionType.Add); break; case PunishType.Ban: Ban ban = new Ban(dPlayer, issuer, reason, GetDate(duration, true), DateTime.Now, DateTime.Now.AddSeconds(GetTotalSeconds(duration, true).TotalSeconds), BanCollection.Find(x => x.Target.Id == dPlayer.Id).Count(), Server.Port, false); ban.Save(); target?.Disconnect(Plugin.Singleton.Config.Translation.BanTranslation.PlayerBanMessage.Replace("{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(ban), dPlayer, ActionType.Add); break; case PunishType.SoftWarn: SoftWarn softWarn = new SoftWarn(dPlayer, issuer, reason, DateTime.Now, SoftWarnCollection.Find(sw => sw.Target.Id == dPlayer.Id).Count(), Server.Port, false); softWarn.Save(); target?.Broadcast( Plugin.Singleton.Config.Translation.SoftWarnTranslation.PlayerSoftWarnedMessage.Duration, Plugin.Singleton.Config.Translation.SoftWarnTranslation.PlayerSoftWarnedMessage.Content.Replace( "{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(softWarn), dPlayer, ActionType.Add); break; case PunishType.SoftBan: SoftBan softBan = new SoftBan(dPlayer, issuer, reason, GetDate(duration), DateTime.Now, DateTime.Now.AddSeconds(GetTotalSeconds(duration).TotalSeconds), SoftBanCollection.Find(sb => sb.Target.Id == dPlayer.Id).Count(), Server.Port, false); softBan.Save(); target?.Broadcast( Plugin.Singleton.Config.Translation.SoftBanTranslation.PlayerSoftBanMessage.Duration, Plugin.Singleton.Config.Translation.StaffTranslation.StaffSoftBanMessage.Content.Replace( "{duration}", GetDate(duration).Replace("{reason}", reason))); if (target != null && target.Role != RoleType.Spectator) { target.Role.Type = RoleType.Spectator; } JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(softBan), dPlayer, ActionType.Add); break; case PunishType.WatchList: WatchList watchList = new WatchList(dPlayer, issuer, reason, DateTime.Now, WatchListCollection.Find(wl => wl.Target.Id == dPlayer.Id).Count(), Server.Port, false); watchList.Save(); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(watchList), dPlayer, ActionType.Add); break; } if (punishType is PunishType.WatchList) { Timing.RunCoroutine(DiscordHandler.SendMessage(Plugin.Singleton.Config.Translation.DiscordTranslation.MessageContentWatchlist.Replace("{target}", $"{dPlayer.Name} ({dPlayer.Id}@{dPlayer.Authentication})").Replace("{reason}", reason).Replace("{issuer}", $"{issuer.Name} ({issuer.Id}@{issuer.Authentication})"), Plugin.Singleton.Config.Translation.DiscordTranslation.WebhookUrlWatchlist)); } Timing.RunCoroutine(DiscordHandler.SendMessage(Plugin.Singleton.Config.Translation.DiscordTranslation.MessageContent.Replace("{target}", $"{dPlayer.Name} ({dPlayer.Id}@{dPlayer.Authentication})").Replace("{reason}", reason).Replace("{action}", punishType.ToString()).Replace("{issuer}", $"{issuer.Name} ({issuer.Id}@{issuer.Authentication})").Replace("{duration}", GetDate(duration, true)), Plugin.Singleton.Config.Translation.DiscordTranslation.WebhookUrl)); }
/// <summary> /// Clear a punish to the specified <see cref="Player"/>. /// </summary> /// <param name="player">The <see cref="Collections.Player"/> player.</param> /// <param name="type"> the <see cref="Enums.PunishType"/>.</param> /// <param name="id"> the punish id.</param> /// <param name="server"> the server port.</param> public static void ClearPunishment(Collections.Player player, PunishType?type, int id, int server) { switch (type) { case PunishType.Ban: Ban ban = BanCollection.FindOne(b => b.Target == player && b.BanId == id && b.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(ban), player, ActionType.Remove); if (player.IsBanned()) { BanHandler.RemoveBan($"{player.Id}@{player.Authentication}", BanHandler.BanType.IP); } BanCollection.Delete(ban.Id); break; case PunishType.Kick: Kick kick = KickCollection.FindOne(k => k.Target == player && k.KickId == id && k.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(kick), player, ActionType.Remove); KickCollection.Delete(kick.Id); break; case PunishType.Mute: Mute mute = MuteCollection.FindOne(m => m.Target == player && m.MuteId == id && m.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(mute), player, ActionType.Remove); if (player.IsMuted()) { MuteHandler.RevokePersistentMute($"{player.Id}@{player.Authentication}"); } MuteCollection.Delete(mute.Id); break; case PunishType.Warn: Warn warn = WarnCollection.FindOne(w => w.Target == player && w.WarnId == id && w.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(warn), player, ActionType.Remove); WarnCollection.Delete(warn.Id); break; case PunishType.SoftWarn: SoftWarn softWarn = SoftWarnCollection.FindOne(sw => sw.Target == player && sw.SoftWarnId == id && sw.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(softWarn), player, ActionType.Remove); SoftWarnCollection.Delete(softWarn.Id); break; case PunishType.SoftBan: SoftBan softBan = SoftBanCollection.FindOne(sb => sb.Target == player && sb.SoftBanId == id && sb.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(softBan), player, ActionType.Remove); SoftBanCollection.Delete(softBan.Id); break; case PunishType.WatchList: WatchList watchList = WatchListCollection.FindOne(wl => wl.Target == player && wl.WatchListId == id && wl.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(watchList), player, ActionType.Remove); WatchListCollection.Delete(watchList.Id); break; } }
protected override Task ExecuteAsync(CancellationToken cancellationToken) { /** * Callback handle that will handle * every message recieved from Behringer X Air */ return(Task.Run(() => { try { log.LogInformation($"Connected to Behringer IP: {host} Port: {port} over UDP"); behringer = new UDPDuplex(host, port, clientPort, callback); log.LogInformation($"Connecting to GpioController"); GpioController controller = new GpioController(PinNumberingScheme.Logical); log.LogInformation($"Starting Background Thread for keepalive"); new Thread(() => KeepAlive()) { IsBackground = true }.Start(); if (tallySettings is List <TallySetting> ) { foreach (var tallySetting in tallySettings) { var handler = new TallyHandler(behringer, controller, tallySetting); tallyHandlers.Add(handler); } } if (muteSettings is List <MuteSetting> ) { foreach (var muteSetting in muteSettings) { var handler = new MuteHandler(behringer, controller, muteSetting); muteHandlers.Add(handler); } } if (muteGroupSettings is List <MuteGroupSetting> ) { foreach (var muteGroupSetting in muteGroupSettings) { var handler = new MuteGroupHandler(behringer, controller, muteGroupSetting); muteGroupHandlers.Add(handler); } } if (talkbackSettings is List <TalkbackSetting> ) { foreach (var talkbackSetting in talkbackSettings) { var handler = new TalkbackHandler(behringer, controller, talkbackSetting); talkbackHandlers.Add(handler); } } if (dcaSettings is List <DcaSetting> ) { foreach (var dcaSetting in dcaSettings) { var handler = new DcaHandler(behringer, controller, dcaSetting); dcaHandlers.Add(handler); } } } catch (Exception e) { log.LogError(e, "BehringerService crashed while running"); throw; } cancellationToken.WaitHandle.WaitOne(); try { foreach (var handler in tallyHandlers) { handler.Close(); } foreach (var handler in muteHandlers) { handler.Close(); } foreach (var handler in muteHandlers) { handler.Close(); } foreach (var handler in talkbackHandlers) { handler.Close(); } foreach (var handler in dcaHandlers) { handler.Close(); } log.LogInformation("UDP connection closed."); behringer.Close(); } catch (Exception e) { log.LogError(e, "BehringerService crashed while terminating"); throw; } })); }
public MuteModule(MuteHandler muteHandler) { this.muteHandler = muteHandler; }