public static async Task GuildBanEventHandlerAsync(TheGodfatherShard shard, GuildBanAddEventArgs e) { DiscordChannel logchn = shard.SharedData.GetLogChannelForGuild(shard.Client, e.Guild); if (logchn == null) { return; } DiscordEmbedBuilder emb = FormEmbedBuilder(EventOrigin.KickOrBan, "Member banned"); var entry = await e.Guild.GetFirstAuditLogEntryAsync(AuditLogActionType.Ban); if (entry == null || !(entry is DiscordAuditLogBanEntry bentry)) { emb.WithDescription(e.Member?.ToString() ?? _unknown); emb.AddField("Error", "Failed to read audit log information. Please check my permissions"); } else { emb.WithDescription(bentry.Target.ToString()); emb.AddField("User responsible", bentry.UserResponsible.Mention, inline: true); if (!string.IsNullOrWhiteSpace(bentry.Reason)) { emb.AddField("Reason", bentry.Reason); } emb.WithFooter(bentry.CreationTimestamp.ToUtcTimestamp(), bentry.UserResponsible.AvatarUrl); } await logchn.SendMessageAsync(embed : emb.Build()); }
public async Task AddUserBannedEventAsync(GuildBanAddEventArgs args) { UserEvent userEvent = new UserEvent() { UserId = args.Member.Id, Username = args.Member.Username, Nickname = args.Member.Nickname, Discriminator = args.Member.Discriminator, AvatarId = args.Member.AvatarHash.ToString(), AccountCreated = args.Member.CreationTimestamp.UtcDateTime, Bot = args.Member.IsBot, Event = Event.Banned, Timestamp = DateTime.Now, }; try { using IServiceScope scope = this.scopeFactory.CreateScope(); using AnalyticsContext db = scope.ServiceProvider.GetRequiredService <AnalyticsContext>(); db.UserEvents.Add(userEvent); await db.SaveChangesAsync(); } catch (Exception e) { Log.Error(e, $"Failed to add new user event {userEvent.Username}#{userEvent.Discriminator} | {userEvent.UserId}"); return; } }
private async Task OnGuildBanAdded(GuildBanAddEventArgs e) { if (GuildBanAdded != null) { await GuildBanAdded(e); } }
public static async Task OnGuildBanAdded(DiscordClient sender, GuildBanAddEventArgs args) { var sanctions = await args.Guild.GetAuditLogsAsync(10, action_type : AuditLogActionType.Kick); var sanction = sanctions.OfType <DiscordAuditLogBanEntry>() .FirstOrDefault(entry => entry.Target == args.Member); if (sanction == null) { return; } var responsible = sanction.UserResponsible; var reason = sanction.Reason ?? "No reason provided."; var usrData = DataContext.GetUserData(args.Guild.Id, args.Member.Id) ?? new UserData { Id = args.Member.Id, GuildId = args.Guild.Id }; usrData.Sanctions ??= new List <Sanction>(); usrData.Sanctions.Add(new Sanction { Type = Sanction.SanctionType.Ban, PunisherId = responsible.Id, IssuedAt = DateTimeOffset.Now, ExpiresAt = DateTimeOffset.MaxValue, Reason = reason }); DataContext.SaveUserData(usrData); sender.Logger.LogInformation(EventIds.Ban, "'{RUsername}#{RDiscriminator}' banned '{PUsername}#{PDiscriminator}' for the following reason: {Reason}", responsible.Username, responsible.Discriminator, args.Member.Username, args.Member.Discriminator, reason); }
private async Task DBLogBanAdded(DiscordClient sender, GuildBanAddEventArgs args) { if (IsSBG(args.Guild.Id)) { await this.userEventService.AddUserBannedEventAsync(args); } }
private async Task GuildBanAdded(DiscordClient c, GuildBanAddEventArgs e) { Task.Run(async() => { await logService.GuildLogger(c, e.Guild, e, LogType.Ban).ConfigureAwait(true); this.logger.Information($"'{e.Member.GetUsertag()}' ({e.Member.Id}) has been banned from '{e.Guild.Name}' ({e.Guild.Id})."); }); }
private async Task OnGuildBanAdded(DiscordClient dClient, GuildBanAddEventArgs args) { if (args.Guild.Id != Guilds.SBG) { return; } IServiceScope scope = this.scopeFactory.CreateScope(); BloonContext db = scope.ServiceProvider.GetRequiredService <BloonContext>(); await db.Database.ExecuteSqlRawAsync("DELETE FROM `role_member` WHERE `id` = {0}", args.Member.Id); }
async Task Client_GuildMemberBanned(GuildBanAddEventArgs e) { try { await e.Guild.GetChannel(691036573713563758).SendMessageAsync(e.Member.Mention + " has been banned.") .Result.CreateReactionAsync(DiscordEmoji.FromUnicode("👋")); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private async Task GuildBanAdded(DiscordClient sender, GuildBanAddEventArgs e) { var banEntry = await GetNewEntryAsync() as DiscordAuditLogBanEntry; _entryBuilder = EmbedBuilderExtensions.CreateForAudit(banEntry, "Бан", $"Пользователь {banEntry.Target.DisplayName} был забанен"); var reason = banEntry.Reason.IsRelevant() ? banEntry.Reason : "Не указана"; _entryBuilder.AddField("Причина", reason); await SendMessageToAuditAsync(embed : _entryBuilder); }
private async Task Client_GuildBanAdded(GuildBanAddEventArgs e) { _logger.Trace($"FilterBot::Client_GuildBanAdded [Guild={e.Guild.Name}, Username={e.Member.Username}]"); var channel = await _client.GetChannel(_config.CommandsChannelId); if (channel == null) { _logger.Error($"Failed to find channel with id {_config.CommandsChannelId}."); return; } await channel.SendMessageAsync($"OH SNAP! The ban hammer was just dropped on {e.Member.Mention}, cya!"); }
private Task Discord_GuildBanAdd(GuildBanAddEventArgs e) { /*var usrn = e.Member.Username? * .Replace(@"\", @"\\") * .Replace(@"*", @"\*") * .Replace(@"_", @"\_") * .Replace(@"~", @"\~") * .Replace(@"`", @"\`"); * * var ch = e.Guild.Channels.FirstOrDefault(xc => xc.Name.Contains("logs")); * if (ch != null) * await ch.SendMessageAsync($"**{usrn}#{e.Member.Discriminator} got bent**");*/ return(Task.Delay(0)); }
private async Task Discord_GuildBanAdd(GuildBanAddEventArgs e) { var usrn = e.User.Username .Replace(@"\", @"\\") .Replace(@"*", @"\*") .Replace(@"_", @"\_") .Replace(@"~", @"\~") .Replace(@"`", @"\`"); var ch = e.Guild.Channels.FirstOrDefault(xc => xc.Name.Contains("logs")); if (ch != null) { await ch.SendMessageAsync($"**{usrn}#{e.User.Discriminator} got bent**"); } }
public static async Task GuildBanEventHandlerAsync(FreudShard shard, GuildBanAddEventArgs e) { var logchn = shard.SharedData.GetLogChannelForGuild(shard.Client, e.Guild); if (logchn is null) { return; } var emb = FormEmbedBuilder(EventOrigin.KickOrBan, "User BANNED"); var entry = await e.Guild.GetLatestAuditLogEntryAsync(AuditLogActionType.Ban); if (entry is null || !(entry is DiscordAuditLogBanEntry bentry)) { emb.WithDescription(e.Member?.ToString() ?? _unknown); emb.AddField("Error", "Failed to read audit log information. Please check my permissions"); }
private async Task Ban(GuildBanAddEventArgs e) { if (e.Client != Client) { var emoji = DiscordEmoji.FromName(this.Client, ":hammer:"); // let's wrap the response into an embed var embed = new DiscordEmbedBuilder { Title = $"ban {emoji}", Description = $"User {e.Client.CurrentUser.Username}.", Color = new DiscordColor(0xFF0000) // red // there are also some pre-defined colors available // as static members of the DiscordColor struct }; await e.Guild.GetChannel(334793139661570058).SendMessageAsync("", embed: embed); } }
private async Task GuildBanAdd(BaseDiscordClient client, Embed embed, GuildBanAddEventArgs guildBanAddEventArgs) { var roles = guildBanAddEventArgs.Member.Roles.Any() ? guildBanAddEventArgs.Member.Roles.Where(x => x.Name != "@everyone") .OrderByDescending(r => r.Position) .Aggregate("", (current, x) => current + $"{x.Mention} ") : "None"; embed.Title = $"{DiscordEmoji.FromGuildEmote(client, EmojiLibrary.Left)} Member banned"; embed.Description = new StringBuilder().AppendLine($"Username: {Formatter.InlineCode(guildBanAddEventArgs.Member.GetUsertag())} {guildBanAddEventArgs.Member.Mention}") .AppendLine($"Identity: {Formatter.InlineCode(guildBanAddEventArgs.Member.Id.ToString())}").ToString(); embed.Color = DiscordColor.IndianRed; embed.Thumbnail = guildBanAddEventArgs.Member.AvatarUrl; embed.Fields = new List <EmbedField> { new EmbedField { Inline = false, Name = "Roles", Value = roles } }; }
internal static Task BanAdded(DiscordClient _1, GuildBanAddEventArgs e) { _ = Task.Run(async() => { if (e.Guild.Id != 699555747591094344) { return; } DiscordAuditLogBanEntry auditLog = (await e.Guild.GetAuditLogsAsync(limit: 5, action_type: AuditLogActionType.Ban)) .First(x => ((DiscordAuditLogBanEntry)x).Target == e.Member) as DiscordAuditLogBanEntry; DiscordEmbedBuilder embed = new DiscordEmbedBuilder() .WithTimestamp(auditLog.CreationTimestamp) .WithDescription($":hammer: {Formatter.Bold("User banned:")} {e.Member.Username}#{e.Member.Discriminator} ({e.Member.Id})\n" + $"\n{Formatter.Bold("Reason:")} {auditLog.Reason}") .WithColor(DiscordColor.DarkRed); await DiscordObjectService.Instance.LogsChannel.SendMessageAsync(embed); }); return(Task.CompletedTask); }
async Task Client_GuildMemberBanned(GuildBanAddEventArgs e) { await e.Guild.GetChannel(691036573713563758).SendMessageAsync(e.Member.Mention + " has been banned.") .Result.CreateReactionAsync(DiscordEmoji.FromUnicode("👋")); }
private Task Client_GuildBanAdded(GuildBanAddEventArgs e) { e.Client.DebugLogger.LogMessage(LogLevel.Info, "BotApp", e.ToString(), DateTime.Now); return(Task.CompletedTask); }
private Task Event_GuildBanAdded(DiscordClient d, GuildBanAddEventArgs e) { d.Logger.LogDebug(BotEventId, "Event_GuildBanAdded."); return(Task.CompletedTask); }
private Task GuildBanAdded(GuildBanAddEventArgs e) { _logger.Information($"'{e.Member.GetUsertag()}' ({e.Member.Id}) has been banned from '{e.Guild.Name}' ({e.Guild.Id})."); return(Task.CompletedTask); }