public void SaveReactiveRegistrationMessage(ReactiveRegistrationMessage config) { Database.Store(config, ReactiveRegistrationMessage.DocumentName(config.GuildId)); }
private async Task ReactiveRegistration(Cacheable <IUserMessage, ulong> messageCache, ISocketMessageChannel channel, SocketReaction reaction) { if (reaction.Emote.Name != registrationConfirmEmoji.Name) { return; } if (!reaction.User.IsSpecified) { return; } if (!(channel is SocketTextChannel guildChannel)) { return; } var user = reaction.User.Value; if (user.IsBot || user.IsWebhook) { return; } var config = Database.Load <ReactiveRegistrationMessage>(ReactiveRegistrationMessage.DocumentName(guildChannel.Guild.Id)); if (config == null) { return; } if (messageCache.Id != config.MessageId) { return; } var competition = GetOrCreateCompetition(guildChannel.Guild.Id); if (user.IsRegistered(this, out var player)) { return; } var limit = Premium.GetRegistrationLimit(Client, guildChannel.Guild); if (limit < competition.RegistrationCount) { var maxErrorMsg = await channel.SendMessageAsync($"{user.Mention} - This server has exceeded the maximum registration count of {limit}, it must be upgraded to premium to allow additional registrations"); var errTask = Task.Run(async() => { await Task.Delay(5000); await maxErrorMsg.DeleteAsync(); }); return; } player = CreatePlayer(guildChannel.Guild.Id, user.Id, user.Username); competition.RegistrationCount++; SaveCompetition(competition); var responses = await UpdateUserAsync(competition, player, user as SocketGuildUser); var responseMsg = await guildChannel.SendMessageAsync($"{user.Mention} - " + competition.FormatRegisterMessage(player) + $"\n{string.Join("\n", responses)}"); var resTask = Task.Run(async() => { await Task.Delay(5000); await responseMsg.DeleteAsync(); }); }
public ReactiveRegistrationMessage GetReactiveRegistrationMessage(ulong guildId) { return(Database.Load <ReactiveRegistrationMessage>(ReactiveRegistrationMessage.DocumentName(guildId))); }