示例#1
0
        private static ulong GetScheduleQueue(DiscordGuildConfiguration guildConfig, bool freshProg, ulong channelId)
        {
#if DEBUG
            return(766712049316265985);
#else
            if (channelId == guildConfig.CastrumScheduleOutputChannel)
            {
                return(765994301850779709);
            }
            else if (channelId == guildConfig.ZadnorThingScheduleOutputChannel)
            {
                return(845106113082818560);
            }
            else if (channelId == guildConfig.DelubrumNormalScheduleOutputChannel)
            {
                return(806957742056013895);
            }
            else if (channelId == guildConfig.DelubrumScheduleOutputChannel)
            {
                if (freshProg)
                {
                    return(809241125373739058);
                }
                return(803636739343908894);
            }
            return(0);
#endif
        }
示例#2
0
        public static IMessageChannel GetOutputChannel(DiscordGuildConfiguration guildConfig, SocketGuild guild, IMessageChannel inputChannel)
        {
            ulong outputChannelId;

            if (inputChannel.Id == guildConfig.ScheduleInputChannel)
            {
                outputChannelId = guildConfig.ScheduleOutputChannel;
            }
            else if (inputChannel.Id == guildConfig.SocialScheduleInputChannel)
            {
                outputChannelId = guildConfig.SocialScheduleOutputChannel;
            }
            else if (inputChannel.Id == guildConfig.ZadnorThingScheduleInputChannel)
            {
                outputChannelId = guildConfig.ZadnorThingScheduleOutputChannel;
            }
            else if (inputChannel.Id == guildConfig.CastrumScheduleInputChannel)
            {
                outputChannelId = guildConfig.CastrumScheduleOutputChannel;
            }
            else if (inputChannel.Id == guildConfig.BozjaClusterScheduleInputChannel)
            {
                outputChannelId = guildConfig.BozjaClusterScheduleOutputChannel;
            }
            else if (inputChannel.Id == guildConfig.DelubrumScheduleInputChannel)
            {
                outputChannelId = guildConfig.DelubrumScheduleOutputChannel;
            }
            else // inputChannel.Id == guildConfig.DelubrumNormalScheduleInputChannel
            {
                outputChannelId = guildConfig.DelubrumNormalScheduleOutputChannel;
            }

            return(guild.GetTextChannel(outputChannelId));
        }
示例#3
0
        public static string GetCalendarCodeForOutputChannel(DiscordGuildConfiguration guildConfig, ulong channelId)
        {
            if (guildConfig == null)
            {
                return(null);
            }

            if (channelId == guildConfig.CastrumScheduleOutputChannel)
            {
                return("cll");
            }
            if (channelId == guildConfig.BozjaClusterScheduleOutputChannel)
            {
                return("bcf");
            }
            if (channelId == guildConfig.DelubrumScheduleOutputChannel)
            {
                return("drs");
            }
            if (channelId == guildConfig.DelubrumNormalScheduleOutputChannel)
            {
                return("dr");
            }
            if (channelId == guildConfig.ZadnorThingScheduleOutputChannel)
            {
                return("zad");
            }
            if (channelId == guildConfig.ScheduleOutputChannel)
            {
                return("ba");
            }
            return(channelId == guildConfig.SocialScheduleOutputChannel ? "social" : null);
        }
示例#4
0
 public async Task AddGuild(DiscordGuildConfiguration config)
 {
     if (!await(await _guildConfig.FindAsync(guild => guild.Id == config.Id)).AnyAsync().ConfigureAwait(false))
     {
         await _guildConfig.InsertOneAsync(config);
     }
 }
示例#5
0
        private async Task <FFXIVDiscordIntegratedQueue> GetEventQueue(DiscordGuildConfiguration guildConfig, IMessage embedMessage, IEmbed eventInfo)
        {
#if DEBUG
            return(_queueService.GetOrCreateQueue(QueueInfo.LfgChannels[766712049316265985]));
#else
            var channelId = embedMessage.Channel.Id;
            if (channelId == guildConfig.DelubrumScheduleOutputChannel)
            {
                if (await DRSIsFreshProg(guildConfig, embedMessage, eventInfo))
                {
                    return(_queueService.GetOrCreateQueue("lfg-drs-fresh-prog"));
                }

                return(_queueService.GetOrCreateQueue("lfg-delubrum-savage"));
            }
            else if (channelId == guildConfig.DelubrumNormalScheduleOutputChannel)
            {
                return(_queueService.GetOrCreateQueue("lfg-delubrum-normal"));
            }
            else if (channelId == guildConfig.CastrumScheduleOutputChannel)
            {
                return(_queueService.GetOrCreateQueue("lfg-castrum"));
            }
            else
            {
                return(null);
            }
#endif
        }
示例#6
0
        public Task AddGuild(DiscordGuildConfiguration config)
        {
            var existing = _guilds.FirstOrDefault(g => g.Id == config.Id);

            if (existing != null)
            {
                return(Task.CompletedTask);
            }
            _guilds.Add(config);
            return(Task.CompletedTask);
        }
示例#7
0
 /// <summary>
 /// Check a message against the text blacklist.
 /// </summary>
 public async Task CheckTextBlacklist(SocketMessage rawMessage, DiscordGuildConfiguration guildConfig)
 {
     foreach (var regexString in guildConfig.TextBlacklist)
     {
         var match = Regex.Match(rawMessage.Content, regexString);
         if (match.Success)
         {
             LastCaughtRegex = regexString;
             await rawMessage.DeleteAsync();
         }
     }
 }
示例#8
0
        private async Task ExecuteCommandAsync(DiscordClient sender, MessageCreateEventArgs e)
        {
            using var scope = this._services.CreateScope();
            var model = scope.ServiceProvider.GetRequiredService <PartnerDatabaseContext>();

            DiscordGuildConfiguration guildConfig = await model.FindAsync <DiscordGuildConfiguration>(e.Guild.Id);

            if (guildConfig is null)
            {
                guildConfig = new DiscordGuildConfiguration
                {
                    GuildId = e.Guild.Id,
                    Prefix  = this._pcfg.Prefix
                };

                model.Add(guildConfig);

                await model.SaveChangesAsync();
            }

            int prefixPos = await PrefixResolver(sender, e.Message, guildConfig);

            if (prefixPos == -1)
            {
                // Prefix is wrong, dont respond to this message.
                return;
            }

            string?prefix        = e.Message.Content.Substring(0, prefixPos);
            string commandString = e.Message.Content.Substring(prefixPos);

            CommandsNextExtension?cnext = sender.GetCommandsNext();

            Command?command = cnext.FindCommand(commandString, out string args);

            if (command is null)
            {
                // Looks like that command does not exsist.
                await this._error.RespondCommandNotFound(e.Channel, prefix);
            }
            else
            {
                // We found a command, lets deal with it.
                CommandContext?ctx = cnext.CreateContext(e.Message, prefix, command, args);
                // We are done here, its up to CommandsNext now.

                await cnext.ExecuteCommandAsync(ctx);
            }
        }
示例#9
0
        private async Task ActivateUser(SocketGuildUser member, DiscordGuildConfiguration guildConfig)
        {
            var memberRole = member.Guild.GetRole(ulong.Parse(guildConfig.Roles["Member"]));
            await member.AddRoleAsync(memberRole);

            Log.Information("Added {DiscordName} to {Role}.", Context.User.ToString(), memberRole.Name);

            var contentRole = member.Guild.GetRole(ulong.Parse(guildConfig.Roles[MostRecentZoneRole]));

            if (contentRole != null)
            {
                await member.AddRoleAsync(contentRole);

                Log.Information("Added {DiscordName} to {Role}.", Context.User.ToString(), contentRole.Name);
            }
        }
示例#10
0
        public async Task SetGuildConfigurationProperty <T>(ulong guildId, string key, T value)
        {
            var existing = _guilds.FirstOrDefault(g => g.Id == guildId);

            if (existing == null)
            {
                existing = new DiscordGuildConfiguration(guildId);
                await AddGuild(existing);
            }

            var field = typeof(DiscordGuildConfiguration).GetField(key);

            if (field == null)
            {
                throw new ArgumentException($"Property {key} does not exist on GlobalConfiguration.");
            }
            field.SetValue(existing, value);
        }
示例#11
0
        private static IMessageChannel GetOutputChannel(DiscordGuildConfiguration guildConfig, SocketGuild guild, IMessageChannel inputChannel)
        {
            ulong outputChannelId;

            if (inputChannel.Id == guildConfig.CastrumScheduleInputChannel)
            {
                outputChannelId = guildConfig.CastrumScheduleOutputChannel;
            }
            else if (inputChannel.Id == guildConfig.DelubrumScheduleInputChannel)
            {
                outputChannelId = guildConfig.DelubrumScheduleOutputChannel;
            }
            else // inputChannel.Id == guildConfig.DelubrumNormalScheduleInputChannel
            {
                outputChannelId = guildConfig.DelubrumNormalScheduleOutputChannel;
            }

            return(guild.GetTextChannel(outputChannelId));
        }
示例#12
0
        private async Task <bool> DRSIsFreshProg(DiscordGuildConfiguration guildConfig, IMessage embedMessage, IEmbed embed)
        {
            if (!embed.Footer.HasValue)
            {
                return(false);
            }
            var eventId = ulong.Parse(embed.Footer.Value.Text);

            var guild        = _client.GetGuild(guildConfig.Id);
            var inputChannel = guild.GetTextChannel(GetScheduleInputChannel(guildConfig, embedMessage.Channel.Id));
            var eventMessage = await inputChannel.GetMessageAsync(eventId);

            var host         = guild.GetUser(eventMessage.Author.Id);
            var discordRoles = DelubrumProgressionRoles.Roles.Keys
                               .Select(rId => guild.GetRole(rId));
            var authorHasProgressionRole = discordRoles.Any(dr => host.HasRole(dr));
            var freshProg = !authorHasProgressionRole || eventMessage.Content.ToLowerInvariant().Contains("810201516291653643");

            return(freshProg);
        }
示例#13
0
 private static ulong GetScheduleInputChannel(DiscordGuildConfiguration guildConfig, ulong channelId)
 {
     if (channelId == guildConfig.CastrumScheduleOutputChannel)
     {
         return(guildConfig.CastrumScheduleInputChannel);
     }
     else if (channelId == guildConfig.DelubrumNormalScheduleOutputChannel)
     {
         return(guildConfig.DelubrumNormalScheduleInputChannel);
     }
     else if (channelId == guildConfig.DelubrumScheduleOutputChannel)
     {
         return(guildConfig.DelubrumScheduleInputChannel);
     }
     else if (channelId == guildConfig.ScheduleOutputChannel)
     {
         return(guildConfig.ScheduleInputChannel);
     }
     return(0);
 }
示例#14
0
        private static ulong GetScheduleInputChannel(DiscordGuildConfiguration guildConfig, ulong channelId)
        {
            var guildConfigFields = typeof(DiscordGuildConfiguration).GetFields();

            var scheduleOutputChannels = guildConfigFields
                                         .Where(f => RegexSearches.ScheduleOutputFieldNameRegex.IsMatch(f.Name))
                                         .ToList();

            foreach (var outputChannelField in scheduleOutputChannels)
            {
                if (channelId != (ulong?)outputChannelField.GetValue(guildConfig))
                {
                    continue;
                }

                var inputChannelFieldName = outputChannelField.Name.Replace("Output", "Input");

                return((ulong?)guildConfigFields
                       .FirstOrDefault(f => f.Name == inputChannelFieldName)
                       ?.GetValue(guildConfig) ?? 0);
            }

            return(0);
        }
示例#15
0
        private static string GetCalendarCode(DiscordGuildConfiguration guildConfig, ulong channelId)
        {
            if (guildConfig == null)
            {
                return(null);
            }

            if (channelId == guildConfig.CastrumScheduleOutputChannel)
            {
                return("cll");
            }
            else if (channelId == guildConfig.DelubrumScheduleOutputChannel)
            {
                return("drs");
            }
            else if (channelId == guildConfig.DelubrumNormalScheduleOutputChannel)
            {
                return("dr");
            }
            else
            {
                return(null);
            }
        }
 public async Task UpdateAsync(DiscordGuildConfiguration discordGuildConfiguration)
 {
     _applicationDbContext.GuildConfigurations.Update(discordGuildConfiguration);
     await _applicationDbContext.SaveChangesAsync();
 }
示例#17
0
        private async Task <int> PrefixResolver(DiscordClient _client, DiscordMessage msg, DiscordGuildConfiguration guildConfig)
        {
            //Checks if bot can't send messages, if so ignore.
            if (!msg.Channel.PermissionsFor(await msg.Channel.Guild.GetMemberAsync(_client.CurrentUser.Id)).HasPermission(Permissions.SendMessages))
            {
                return(-1);
            }

            string?parts = msg.Content.Split(" ", StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

            if (parts is not null)
            {
                var trimed = parts.Replace("!", "");
                if (trimed.StartsWith(_client.CurrentUser.Mention))
                {
                    return(parts.Length);
                }
            }

            // Always respond to a mention.
            if (msg.Content.StartsWith(_client.CurrentUser.Mention))
            {
                return(_client.CurrentUser.Mention.Length);
            }
            else
            {
                try
                {
                    if (guildConfig.Prefix is null)
                    {
                        guildConfig.Prefix = this._pcfg.Prefix;
                    }

                    if (msg.Content.StartsWith(guildConfig.Prefix))
                    {
                        //Return length of server prefix.
                        return(guildConfig?.Prefix?.Length ?? -1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                catch (Exception err)
                {
                    this._logger.LogError(DiscordBot.Event_CommandHandler, err, $"Prefix Resolver failed in guild {msg.Channel.Guild.Name}:");
                    return(-1);
                }
            }
        }
    public async Task SaveAsync(DiscordGuildConfiguration discordGuildConfiguration)
    {
        await _applicationDbContext.GuildConfigurations.AddAsync(discordGuildConfiguration);

        await _applicationDbContext.SaveChangesAsync();
    }
示例#19
0
        private static async Task TryNotifyMember(IUser member, IGuildUser leader, ISocketMessageChannel commandChannel, ScheduledEvent @event, DiscordGuildConfiguration guildConfig, CancellationToken token)
        {
            var success = false;

            try
            {
                await member.SendMessageAsync(
                    $"The run you reacted to (hosted by {leader.Nickname ?? leader.Username}) is beginning in 30 minutes!\n\n" +
                    $"Message link: <{(await commandChannel.GetMessageAsync(@event.MessageId3)).GetJumpUrl()}>");

                success = true;
            }
            catch (HttpException)
            {
                try
                {
                    var message = await commandChannel.SendMessageAsync($"{member.Mention}, the run you reacted to (hosted by {leader.Nickname ?? leader.Username}) is beginning in 30 minutes!\n\n" +
                                                                        $"Message link: <{(await commandChannel.GetMessageAsync(@event.MessageId3)).GetJumpUrl()}>");

                    (new Task(async() =>
                    {
                        await Task.Delay((int)Threshold, token);
                        try
                        {
                            await message.DeleteAsync();
                        }
                        catch (HttpException) { } // Message was already deleted.
                    })).Start();
                    success = true;
                }
                catch (HttpException)
                {
                    Log.Warning("Every attempt at message user {Username} failed.", member.ToString());
                }
            }
            if (success)
            {
                Log.Information($"Info sent to {member} about {leader}'s run.");
            }
        }
示例#20
0
        /// <summary>
        /// Check a message against the text greylist.
        /// </summary>
        private static async Task CheckTextGreylist(SocketGuild guild, IMessage rawMessage, DiscordGuildConfiguration guildConfig, ITemplateProvider templates)
        {
            if (guildConfig.TextGreylist == null)
            {
                Log.Warning("{List} is null.", nameof(guildConfig.TextGreylist));
                return;
            }

            foreach (var regexString in guildConfig.TextGreylist)
            {
                var match = Regex.Match(rawMessage.Content, regexString);
                if (match.Success)
                {
                    LastCaughtRegex = regexString;
                    var reportChannel = guild.GetTextChannel(guildConfig.ReportChannel);
                    if (reportChannel == null)
                    {
                        Log.Warning("No report channel configured for softblocked message!");
                        return;
                    }

                    await reportChannel.SendMessageAsync(embed : templates.Execute("automod/softblock.md", new
                    {
                        ChannelName = rawMessage.Channel.Name,
                        MessageText = rawMessage.Content,
                        Pattern = regexString,
                        JumpLink = rawMessage.GetJumpUrl(),
                    })
                                                         .ToEmbedBuilder()
                                                         .WithColor(Color.Orange)
                                                         .Build());
                }
            }
        }
示例#21
0
        /// <summary>
        /// Check a message against the text denylist.
        /// </summary>
        private static async Task CheckTextDenylist(SocketGuild guild, IMessage rawMessage, DiscordGuildConfiguration guildConfig, ITemplateProvider templates)
        {
            foreach (var regexString in guildConfig.TextDenylist)
            {
                var match = Regex.Match(rawMessage.Content, regexString);
                if (match.Success)
                {
                    LastCaughtRegex = regexString;
                    await rawMessage.DeleteAsync();

                    await rawMessage.Author.SendMessageAsync(embed : templates.Execute("automod/delete.md", new
                    {
                        ChannelName = rawMessage.Channel.Name,
                        MessageText = rawMessage.Content,
                        Pattern = regexString,
                    })
                                                             .ToEmbedBuilder()
                                                             .WithColor(Color.Orange)
                                                             .Build());
                }
            }
        }