예제 #1
0
        // Private members

        private static async Task <string> ReplyUploadFileToScratchChannelAsync(this OfcModuleBase moduleBase, string filePath)
        {
            ulong serverId  = moduleBase.Config.ScratchServer;
            ulong channelId = moduleBase.Config.ScratchChannel;

            if (serverId <= 0 || channelId <= 0)
            {
                await moduleBase.ReplyErrorAsync("Cannot upload images because no scratch server/channel has been specified in the configuration file.");

                return(string.Empty);
            }

            IGuild guild = moduleBase.DiscordClient.GetGuild(serverId);

            if (guild is null)
            {
                await moduleBase.ReplyErrorAsync("Cannot upload images because the scratch server is inaccessible.");

                return(string.Empty);
            }

            ITextChannel channel = await guild.GetTextChannelAsync(channelId);

            if (channel is null)
            {
                await moduleBase.ReplyErrorAsync("Cannot upload images because the scratch channel is inaccessible.");

                return(string.Empty);
            }

            return(await DiscordUtilities.UploadFileAsync(channel, filePath, FileUploadOptions.DeleteFileAfterUpload));
        }
예제 #2
0
        public static async Task <bool> ReplyValidateZoneAsync(this OfcModuleBase moduleBase, IZone zone, string zoneName = "")
        {
            if (!zone.IsValid())
            {
                string message = "No such zone exists.";

                if (!string.IsNullOrEmpty(zoneName))
                {
                    zoneName = ZoneUtilities.GetFullName(zoneName);

                    if (zoneName.StartsWith("zone", System.StringComparison.OrdinalIgnoreCase))
                    {
                        message = $"{zoneName.ToTitle().ToBold()} does not exist.";
                    }
                    else
                    {
                        message = $"Zone {zoneName.ToTitle().ToBold()} does not exist.";
                    }
                }

                await DiscordUtilities.ReplyErrorAsync(moduleBase.Context.Channel, message);

                return(false);
            }

            return(true);
        }
예제 #3
0
        // Public members

        public static async Task <IZone> GetZoneOrReplyAsync(this OfcModuleBase moduleBase, string zoneName)
        {
            IZone zone = await moduleBase.Db.GetZoneAsync(zoneName);

            await moduleBase.ReplyValidateZoneAsync(zone, zoneName);

            return(zone);
        }
예제 #4
0
        public static async Task <IRole> GetRoleOrReplyAsync(this OfcModuleBase moduleBase, string roleName)
        {
            IRole role = await moduleBase.Db.GetRoleAsync(roleName);

            await moduleBase.ReplyValidateRoleAsync(role);

            return(role);
        }
        public static async Task ScanTrophiesAsync(this OfcModuleBase moduleBase, ICreator creator, bool scanImmediately = false)
        {
            if (moduleBase.TrophyScanner != null && moduleBase.Config.TrophiesEnabled)
            {
                ITrophyScannerContext context = new TrophyScannerContext(moduleBase.Context, creator, await moduleBase.GetDatabaseAsync());

                await moduleBase.TrophyScanner.EnqueueAsync(context, scanImmediately);
            }
        }
예제 #6
0
        public static async Task <bool> ReplyValidateGotchiAsync(this OfcModuleBase moduleBase, Gotchi gotchi)
        {
            if (!gotchi.IsValid())
            {
                await moduleBase.ReplyInfoAsync("You don't have a gotchi yet! Get one with `gotchi get <species>`.");

                return(false);
            }

            return(true);
        }
예제 #7
0
        // Public members

        public static async Task <Gotchi> GetGotchiOrReplyAsync(this OfcModuleBase moduleBase, ICreator creator)
        {
            Gotchi gotchi = await moduleBase.Db.GetGotchiAsync(creator);

            if (await moduleBase.ReplyValidateGotchiAsync(gotchi))
            {
                return(gotchi);
            }

            return(null);
        }
예제 #8
0
        public static async Task <bool> ReplyValidateRoleAsync(this OfcModuleBase moduleBase, IRole role)
        {
            if (!role.IsValid())
            {
                await moduleBase.ReplyErrorAsync("No such role exists.");

                return(false);
            }

            return(true);
        }
예제 #9
0
        public static async Task <string> ReplyUploadGotchiGifAsync(this OfcModuleBase moduleBase, Gotchi gotchi)
        {
            string filePath = await moduleBase.Db.CreateGotchiGifAsync(gotchi);

            string uploadUrl = string.Empty;

            if (!string.IsNullOrEmpty(filePath))
            {
                uploadUrl = await moduleBase.ReplyUploadFileToScratchChannelAsync(filePath);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                await moduleBase.ReplyErrorAsync("The gotchi image could not be created.");
            }
            else if (string.IsNullOrEmpty(uploadUrl))
            {
                await moduleBase.ReplyErrorAsync("The gotchi image could not be uploaded.");
            }

            return(uploadUrl);
        }
        public static async Task <IPaginatedMessage> BuildRecentEventsMessageAsync(this OfcModuleBase moduleBase, DateTimeOffset start, DateTimeOffset end)
        {
            IEnumerable <ISpecies> newSpecies     = (await moduleBase.Db.GetSpeciesAsync(start, end)).OrderBy(species => moduleBase.TaxonFormatter.GetString(species, false));
            IEnumerable <ISpecies> extinctSpecies = (await moduleBase.Db.GetExtinctSpeciesAsync(start, end)).OrderBy(species => moduleBase.TaxonFormatter.GetString(species, false));

            List <IEmbed> pages = new List <IEmbed>();

            if (newSpecies.Count() > 0)
            {
                EmbedUtilities.AppendEmbedPages(pages, EmbedUtilities.CreateEmbedPages($"New species ({newSpecies.Count()})", newSpecies.Select(species => moduleBase.TaxonFormatter.GetString(species))));
            }

            if (extinctSpecies.Count() > 0)
            {
                EmbedUtilities.AppendEmbedPages(pages, EmbedUtilities.CreateEmbedPages($"Extinctions ({extinctSpecies.Count()})", extinctSpecies.Select(species => moduleBase.TaxonFormatter.GetString(species, false))));
            }

            EmbedUtilities.AddPageNumbers(pages);

            if (pages.Count() <= 0)
            {
                pages.Add(new Embed()
                {
                    Description = "No events"
                });
            }

            foreach (IEmbed page in pages)
            {
                page.Title = $"Recent events ({DateUtilities.GetTimeSpanString(end - start)})";
            }

            IPaginatedMessage message = new PaginatedMessage(pages);

            return(message);
        }
        public static async Task ReplyRecentEventsAsync(this OfcModuleBase moduleBase, DateTimeOffset start, DateTimeOffset end)
        {
            IPaginatedMessage message = await moduleBase.BuildRecentEventsMessageAsync(start, end);

            await moduleBase.ReplyAsync(message);
        }