Ejemplo n.º 1
0
        public async Task LeaveAsync(IGuildUser?guildUser)
        {
            if (guildUser == null)
            {
                return;
            }

            var userInGuild = guildData.GetUser(guildUser.Id);

            if (userInGuild == null)
            {
                await Context.Message.ReplyAsync($"User is not on the waiting list!");
            }
            else
            {
                userInGuild.IsInWaitingList = false;
                userInGuild.JoinTime        = default;
                dataContext.Update(userInGuild);
                dataContext.SaveChanges();

                await Context.Message.ReplyAsync($"User left the waiting list!");

                await ButtonWaitingListModule.UpdatePublicMessageAsync(waitingList, Context.Guild, guildData);
            }
        }
Ejemplo n.º 2
0
        public async Task SetCounterAsync(IGuildUser guildUser, int counter)
        {
            if (guildUser == null)
            {
                return;
            }

            if (!guildData.IsEnabled)
            {
                await Context.Message.ReplyAsync("The waiting list is closed.");

                return;
            }

            var userInGuild = guildData.GetOrCreateGuildUser(guildUser.Id, guildUser.Nickname ?? guildUser.Username);

            // Add user the the waiting list
            userInGuild.PlayCount = counter;
            dataContext.Update(userInGuild);
            dataContext.SaveChanges();

            await Context.Message.ReplyAsync($"Updated counter for {userInGuild.Name}");

            await ButtonWaitingListModule.UpdatePublicMessageAsync(waitingList, Context.Guild, guildData);
        }
Ejemplo n.º 3
0
        public async Task PlayAsync(IGuildUser guildUser)
        {
            if (guildUser == null)
            {
                return;
            }

            if (!guildData.IsEnabled)
            {
                await Context.Message.ReplyAsync("The waiting list is closed.");

                return;
            }

            var userInGuild = guildData.GetOrCreateGuildUser(guildUser.Id, guildUser.Nickname ?? guildUser.Username);

            if (userInGuild.IsInWaitingList)
            {
                await Context.Message.ReplyAsync("You are already on the waiting list!");
            }
            else
            {
                // Add user the the waiting list
                userInGuild.IsInWaitingList = true;
                userInGuild.JoinTime        = DateTime.Now;
                userInGuild.IsSub           = guildUser.RoleIds.Contains(guildData.SubRoleId);
                dataContext.Update(userInGuild);
                dataContext.SaveChanges();

                await Context.Message.ReplyAsync($"Waiting list joined!");

                await ButtonWaitingListModule.UpdatePublicMessageAsync(waitingList, Context.Guild, guildData);
            }
        }
Ejemplo n.º 4
0
        public async Task ClearCountersAsync()
        {
            foreach (var guildUser in guildData.UsersInList)
            {
                guildUser.PlayCount = 0;
                dataContext.Update(guildUser);
            }
            dataContext.SaveChanges();

            await ButtonWaitingListModule.UpdatePublicMessageAsync(waitingList, Context.Guild, guildData);

            await Context.Message.ReplyAsync("Counters have been cleared");
        }
Ejemplo n.º 5
0
        public async Task ClearWaitingListAsync()
        {
            foreach (var guildUser in guildData.UsersInGuild)
            {
                guildUser.IsInWaitingList = false;
                guildUser.PlayCount       = 0;
                guildUser.JoinTime        = default;
                dataContext.Update(guildUser);
            }
            dataContext.SaveChanges();

            await ButtonWaitingListModule.UpdatePublicMessageAsync(waitingList, Context.Guild, guildData);

            await Context.Channel.SendFileAsync("nuke.jpg", "List has been cleared");
        }
Ejemplo n.º 6
0
        private async Task InviteNextUsersAsync(int numberOfPlayers, string[] arguments, ulong?inviteRole = null, bool?isInviteRolePositive = null)
        {
            try
            {
                var(result, invite) = await waitingList.GetInvite(arguments, numberOfPlayers, inviteRole, isInviteRolePositive, removeFromList : true);

                logger.LogInformation(result?.Message);

                if (!result.Success || invite == null)
                {
                    await Context.Message.ReplyAsync(result.Message);

                    return;
                }

                string playerString = "";

                foreach (var invitedUser in invite.InvitedUsers)
                {
                    playerString += invitedUser.User.Name + " (" + MentionUtils.MentionUser(invitedUser.User.UserId) + ") ";
                }

                var inviteMessage = await Context.Message.ReplyAsync(result.Message + "\r\nInvited players: " + playerString, allowedMentions : AllowedMentions.None);

                invite.InviteMessageChannelId = inviteMessage.Channel.Id;
                invite.InviteMessageId        = inviteMessage.Id;

                dataContext.Update(invite);
                dataContext.SaveChanges();

                await ButtonWaitingListModule.UpdatePublicMessageAsync(waitingList, Context.Guild, guildData);
                await UpdateInviteMessageAsync(Context.Guild, invite);
            }
            catch (Exception ex)
            {
                var user = await Context.Client.Rest.GetUserAsync(367018778409566209);

                var myDMChannel = await user.CreateDMChannelAsync();

                await myDMChannel.SendMessageAsync("Server: " + Context.Guild.Name);

                await myDMChannel.SendMessageAsync(ex.ToString());

                logger.LogError(ex, "Failed to invite players");

                throw;
            }
        }