Exemple #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));
        }
Exemple #2
0
        public async Task <string> UploadFileAsync(string filePath, IMessageChannel channel = null, FileUploadOptions options = FileUploadOptions.None)
        {
            if (channel is null)
            {
                ulong serverId  = config.ScratchServer;
                ulong channelId = config.ScratchChannel;

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

                IGuild guild = client.GetGuild(serverId);

                if (guild is null)
                {
                    throw new Exception("Cannot upload images because the scratch server is inaccessible.");
                }

                channel = await guild.GetTextChannelAsync(channelId);

                if (channel is null)
                {
                    throw new Exception("Cannot upload images because the scratch channel is inaccessible.");
                }
            }

            return(await DiscordUtilities.UploadFileAsync(channel, filePath, options));
        }