private static async Task PunishUsers(PunishmentAction action, ProtectionType pt, params IGuildUser[] gus) { _log.Info($"[{pt}] - Punishing [{gus.Length}] users with [{action}] in {gus[0].Guild.Name} guild"); foreach (var gu in gus) { switch (action) { case PunishmentAction.Mute: try { await MuteCommands.MuteUser(gu).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Kick: try { await gu.KickAsync().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Softban: try { await gu.Guild.AddBanAsync(gu, 7).ConfigureAwait(false); try { await gu.Guild.RemoveBanAsync(gu).ConfigureAwait(false); } catch { await gu.Guild.RemoveBanAsync(gu).ConfigureAwait(false); // try it twice, really don't want to ban user if // only kick has been specified as the punishement } } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; case PunishmentAction.Ban: try { await gu.Guild.AddBanAsync(gu, 7).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; } } await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false); }
private async Task PunishUsers(PunishmentAction action, IRole muteRole, ProtectionType pt, params IGuildUser[] gus) { foreach (var gu in gus) { switch (action) { case PunishmentAction.Mute: try { await gu.AddRolesAsync(muteRole); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); } break; case PunishmentAction.Kick: try { await gu.Guild.AddBanAsync(gu, 7); try { await gu.Guild.RemoveBanAsync(gu); } catch { await gu.Guild.RemoveBanAsync(gu); // try it twice, really don't want to ban user if // only kick has been specified as the punishement } } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; case PunishmentAction.Ban: try { await gu.Guild.AddBanAsync(gu, 7); } catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); } break; default: break; } } await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false); }