Beispiel #1
0
        public bool CanCreate(TicketGuild guild, IGuildUser user)
        {
            //Allow all roles if the creator whitelist is empty
            if (!guild.TicketCreatorWhitelist.Any())
            {
                return(true);
            }

            //Allow admins and the server owner always
            if (user.GuildPermissions.Administrator || user.Guild.OwnerId == user.Id)
            {
                return(true);
            }

            //Allow anyone who is given a ticket manager role
            if (user.RoleIds.Any(x => guild.TicketManagers.Contains(x)))
            {
                return(true);
            }

            //Allow anyone who is given a ticket creator role
            if (user.RoleIds.Any(x => guild.TicketCreatorWhitelist.Contains(x)))
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public TicketGuild GetTicketGuild(ulong guildId)
        {
            var guild = Database.Load <TicketGuild>(TicketGuild.DocumentName(guildId));

            if (guild == null)
            {
                guild = new TicketGuild(guildId);
                SaveGuild(guild);
            }

            return(guild);
        }
Beispiel #3
0
        //Sets or updates the live message
        //TODO: Schedule message updates to reduce ratelimit issues in larger servers causing the bot to be laggy or display incorrect vote count
        public async Task <IUserMessage> UpdateLiveMessageAsync(SocketGuild guild, TicketGuild tGuild, Ticket ticket)
        {
            if (tGuild.TicketChannelId != 0)
            {
                var channel = guild.GetTextChannel(tGuild.TicketChannelId);
                if (channel != null)
                {
                    if (ticket.LiveMessageId == 0)
                    {
                        var msg = await channel.SendMessageAsync("", false, ticket.GenerateEmbed(guild, tGuild.UseVoting).Build());

                        ticket.LiveMessageId = msg.Id;
                        SaveTicket(ticket);
                        return(msg);
                    }

                    var message = await channel.GetMessageAsync(ticket.LiveMessageId);

                    if (message != null)
                    {
                        if (message is IUserMessage msg)
                        {
                            await msg.ModifyAsync(x => x.Embed = ticket.GenerateEmbed(guild, tGuild.UseVoting).Build());

                            SaveTicket(ticket);
                            return(msg);
                        }
                    }
                    else
                    {
                        var msg = await channel.SendMessageAsync("", false, ticket.GenerateEmbed(guild, tGuild.UseVoting).Build());

                        ticket.LiveMessageId = msg.Id;
                        SaveTicket(ticket);
                        return(msg);
                    }
                }
            }

            return(null);
        }
Beispiel #4
0
        public bool IsManager(TicketGuild guild, IGuildUser user, Ticket ticket = null)
        {
            //Allow admins and the server owner always
            if (user.GuildPermissions.Administrator || user.Guild.OwnerId == user.Id)
            {
                return(true);
            }

            //Allow anyone who is given a ticket manager role
            if (user.RoleIds.Any(x => guild.TicketManagers.Contains(x)))
            {
                return(true);
            }

            //Allow the creator of the ticket to manage it
            if (ticket != null && ticket.AuthorId == user.Id)
            {
                return(true);
            }

            return(false);
        }
Beispiel #5
0
 public void SaveGuild(TicketGuild guild)
 {
     Database.Store(guild, TicketGuild.DocumentName(guild.GuildId));
 }