public async ValueTask HandleJoinedGuild(object sender, JoinedGuildEventArgs e) { foreach (var service in JoinedGuildServices) { await ExecuteAsync((service, e) => service.OnJoinedGuild(e), service, e).ConfigureAwait(false); } }
private async Task OnGuildJoined(JoinedGuildEventArgs args) { var guild = args.Guild; this._logger.LogInformation("Joined {guild} with {members} members", guild.Name, guild.MemberCount); using var scope = this.CreateScope(); await using var context = scope.ServiceProvider.GetRequiredService <EspeonDbContext>(); await PersistGuildAsync(guild, context); }
private async Task OnJoinAsync(JoinedGuildEventArgs args) { _logger.Debug(LogSource.Volte, "Joined a guild."); if (Config.BlacklistedOwners.Contains(args.Guild.Owner.Id)) { _logger.Warn(LogSource.Volte, $"Left guild \"{args.Guild.Name}\" owned by blacklisted owner {args.Guild.Owner}."); await args.Guild.LeaveAsync(); return; } var embed = new EmbedBuilder() .WithTitle("Hey there!") .WithAuthor(args.Guild.Owner) .WithColor(Config.SuccessColor) .WithDescription("Thanks for inviting me! Here's some basic instructions on how to set me up.") .AddField("Set your admin role", "$adminrole {roleName}", true) .AddField("Set your moderator role", "$modrole {roleName}", true) .AddField("Permissions", new StringBuilder() .AppendLine("It is recommended to give me admin permission, to avoid any permission errors that may happen.") .AppendLine("You *can* get away with just send messages, ban members, kick members, and the like if you don't want to give me admin.") .ToString()) .AddField("Support Server", "[Join my support Discord here](https://discord.gg/H8bcFr2)"); _logger.Debug(LogSource.Volte, "Attempting to send the guild owner the introduction message."); try { await embed.SendToAsync(args.Guild.Owner); _logger.Error(LogSource.Volte, "Sent the guild owner the introduction message."); } catch (HttpException ex) when(ex.HttpCode is HttpStatusCode.Forbidden) { var c = args.Guild.TextChannels.OrderByDescending(x => x.Position).FirstOrDefault(); _logger.Error(LogSource.Volte, "Could not DM the guild owner; sending to the upper-most channel instead."); if (c != null) { await embed.SendToAsync(c); } } if (!Config.GuildLogging.EnsureValidConfiguration(_client, out var channel)) { _logger.Error(LogSource.Volte, "Invalid guild_logging.guild_id/guild_logging.channel_id configuration. Check your IDs and try again."); return; } var all = args.Guild.Users; var users = all.Where(u => !u.IsBot).ToList(); var bots = all.Where(u => u.IsBot).ToList(); var e = new EmbedBuilder() .WithAuthor(args.Guild.Owner) .WithTitle("Joined Guild") .AddField("Name", args.Guild.Name, true) .AddField("ID", args.Guild.Id, true) .WithThumbnailUrl(args.Guild.IconUrl) .WithCurrentTimestamp() .AddField("Users", users.Count(), true) .AddField("Bots", bots.Count(), true); if (bots.Count() > users.Count()) { await channel.SendMessageAsync( $"{_client.GetOwner().Mention}: Joined a guild with more bots than users.", false, e.WithSuccessColor().Build()); } else { await e.WithSuccessColor().SendToAsync(channel); } }
protected internal virtual ValueTask OnJoinedGuild(JoinedGuildEventArgs e) => default;