internal async Task JoinAsync(UserJoinedEventArgs args) { var data = _db.GetData(args.Guild); if (data.Configuration.Welcome.WelcomeMessage.IsNullOrEmpty()) { return; //we don't want to send an empty join message } if (!data.Configuration.Welcome.WelcomeDmMessage.IsNullOrEmpty()) { _ = await args.User.TrySendMessageAsync(data.Configuration.Welcome.FormatDmMessage(args.User)); } _logger.Debug(LogSource.Volte, "User joined a guild, let's check to see if we should send a welcome embed."); var welcomeMessage = data.Configuration.Welcome.FormatWelcomeMessage(args.User); var c = args.Guild.GetTextChannel(data.Configuration.Welcome.WelcomeChannel); if (!(c is null)) { await new EmbedBuilder() .WithColor(data.Configuration.Welcome.WelcomeColor) .WithDescription(welcomeMessage) .WithThumbnailUrl(args.User.GetAvatarUrl()) .WithCurrentTimestamp() .SendToAsync(c); _logger.Debug(LogSource.Volte, $"Sent a welcome embed to #{c.Name}."); return; } _logger.Debug(LogSource.Volte, "WelcomeChannel config value resulted in an invalid/nonexistent channel; aborting."); }
public async Task OnShardReadyAsync(ShardReadyEventArgs args) { var guilds = args.Shard.Guilds.Count; var users = args.Shard.Guilds.SelectMany(x => x.Users).DistinctBy(x => x.Id).Count(); var channels = args.Shard.Guilds.SelectMany(x => x.Channels).DistinctBy(x => x.Id).Count(); _logger.PrintVersion(); _logger.Info(LogSource.Volte, "Use this URL to invite me to your guilds:"); _logger.Info(LogSource.Volte, $"{args.Shard.GetInviteUrl()}"); _logger.Info(LogSource.Volte, $"Logged in as {args.Shard.CurrentUser}, shard {args.Shard.ShardId}"); _logger.Info(LogSource.Volte, $"Default command prefix is: \"{Config.CommandPrefix}\""); _logger.Info(LogSource.Volte, "Connected to:"); _logger.Info(LogSource.Volte, $" {"guild".ToQuantity(guilds)}"); _logger.Info(LogSource.Volte, $" {"user".ToQuantity(users)}"); _logger.Info(LogSource.Volte, $" {"channel".ToQuantity(channels)}"); if (!_shouldStream) { if (_shouldSetGame) { await args.Shard.SetGameAsync(Config.Game); _logger.Info(LogSource.Volte, $"Set {args.Shard.CurrentUser.Username}'s game to \"{Config.Game}\"."); } } else { await args.Shard.SetGameAsync(Config.Game, Config.FormattedStreamUrl, ActivityType.Streaming); _logger.Info(LogSource.Volte, $"Set {args.Shard.CurrentUser.Username}'s activity to \"{ActivityType.Streaming}: {Config.Game}\", at Twitch user {Config.Streamer}."); } _ = Task.Run(async() => { foreach (var guild in args.Shard.Guilds) { if (Config.BlacklistedOwners.Contains(guild.OwnerId)) { _logger.Warn(LogSource.Volte, $"Left guild \"{guild.Name}\" owned by blacklisted owner {guild.Owner}."); await guild.LeaveAsync(); } _ = _db.GetData(guild); //ensuring all guilds have data available to prevent exceptions later on } }); if (Config.GuildLogging.EnsureValidConfiguration(args.Client, out var channel)) { await new EmbedBuilder() .WithSuccessColor() .WithAuthor(args.Client.GetOwner()) .WithDescription( $"Volte {Version.FullVersion} is starting at **{DateTimeOffset.UtcNow.FormatFullTime()}, on {DateTimeOffset.UtcNow.FormatDate()}**!") .SendToAsync(channel); } }
private EvalEnvironment CreateEvalEnvironment(VolteContext ctx) => new EvalEnvironment { Context = ctx, Client = ctx.Client.GetShardFor(ctx.Guild), Data = _db.GetData(ctx.Guild), Logger = _logger, CommandService = _commands, DatabaseService = _db, EmojiService = _emoji };
private EvalObjects GetEvalObjects(VolteContext ctx) => new EvalObjects { Context = ctx, Client = ctx.Client.GetShardFor(ctx.Guild), Data = _db.GetData(ctx.Guild), Logger = _logger, CommandService = _commands, DatabaseService = _db, EmojiService = _emoji };
private async Task ApplyRoleAsync(UserJoinedEventArgs args) { var data = _db.GetData(args.Guild); var targetRole = args.Guild.GetRole(data.Configuration.Autorole); if (targetRole is null) { _logger.Debug(LogSource.Volte, $"Guild {args.Guild.Name}'s Autorole is set to an ID of a role that no longer exists; or is not set at all."); return; } await args.User.AddRoleAsync(targetRole); _logger.Debug(LogSource.Volte, $"Applied role {targetRole.Name} to user {args.User} in guild {args.Guild.Name}."); }
public async Task OnReady(ReadyEventArgs args) { var guilds = args.Client.Guilds.Count; var users = args.Client.Guilds.SelectMany(x => x.Users).DistinctBy(x => x.Id).Count(); var channels = args.Client.Guilds.SelectMany(x => x.Channels).DistinctBy(x => x.Id).Count(); _logger.PrintVersion(); _logger.Info(LogSource.Volte, "Use this URL to invite me to your guilds:"); _logger.Info(LogSource.Volte, $"{args.Client.GetInviteUrl()}"); _logger.Info(LogSource.Volte, $"Logged in as {args.Client.CurrentUser}"); _logger.Info(LogSource.Volte, "Connected to:"); _logger.Info(LogSource.Volte, $" {"guild".ToQuantity(guilds)}"); _logger.Info(LogSource.Volte, $" {"user".ToQuantity(users)}"); _logger.Info(LogSource.Volte, $" {"channel".ToQuantity(channels)}"); if (_shouldStream) { await args.Client.SetGameAsync(Config.Game); _logger.Info(LogSource.Volte, $"Set the bot's game to {Config.Game}."); } else { await args.Client.SetGameAsync(Config.Game, Config.FormattedStreamUrl, ActivityType.Streaming); _logger.Info(LogSource.Volte, $"Set the bot's activity to \"{ActivityType.Streaming} {Config.Game}, at {Config.FormattedStreamUrl}\"."); } foreach (var guild in args.Client.Guilds) { if (Config.BlacklistedOwners.Contains(guild.OwnerId)) { _logger.Warn(LogSource.Volte, $"Left guild \"{guild.Name}\" owned by blacklisted owner {guild.Owner}."); await guild.LeaveAsync(); } _ = _db.GetData(guild); //ensuring all guilds have data available, to prevent exceptions later on } }
/// <summary> /// Verifies if a given reaction operation is for a valid starboard reaction (star emoji, not DM, not made by /// the bot, and a starboard channel exists). /// </summary> /// <param name="channel">The channel the reaction was sent in</param> /// <param name="reaction">The reaction</param> /// <param name="starboard">Will be assigned to retrieved starboard information</param> /// <param name="starboardChannel">Will be assigned to the <see cref="SocketChannel"/> for the starboard channel</param> /// <returns>True if the reaction is valid, false otherwise</returns> private bool IsStarReaction( IMessageChannel channel, SocketReaction reaction, out StarboardOptions starboard, out SocketChannel starboardChannel) { starboard = default; starboardChannel = default; // Ignore reaction events sent in DMs if (!(channel is IGuildChannel guildChannel)) { return(false); } // Ignore non-star reactions if (reaction.Emote.Name != _starEmoji.Name) { return(false); } // Ignore reactions from the current user if (reaction.UserId == _client.CurrentUser.Id) { return(false); } var data = _db.GetData(guildChannel.Guild.Id); starboard = data.Configuration.Starboard; if (!starboard.Enabled) { return(false); } starboardChannel = _client.GetChannel(starboard.StarboardChannel); return(!(starboardChannel is null)); }