public static async Task <RedditAPI> EstablishApiIfNecessaryAndGet(MessageContext context,
                                                                           int timeout          = Reddit.DefaultTimeout,
                                                                           bool displayMessages = true)
        {
            if (!displayMessages)
            {
                return(await Reddit.EstablishApiIfNecessaryAndGet(timeout).ConfigureAwait(false));
            }

            RedditAPI reddit;

            if (!Reddit.ApiIsEstablished())
            {
                await context.Reply("It appears the connection to the Reddit API has failed... Attempting to reestablish").ConfigureAwait(false);

                reddit = await Reddit.EstablishApiAndGet(timeout).ConfigureAwait(false);
            }
            else
            {
                reddit = Reddit.Api;
            }

            if (reddit == null)
            {
                await context.Reply("Error: a connection to the Reddit API could not be established.").ConfigureAwait(false);
            }

            return(reddit);
        }
Ejemplo n.º 2
0
        protected override async Task _Invoke(MessageContext context)
        {
            DiscordMessage checkingMessage = await context.Reply("Checking reddit API connection status...").ConfigureAwait(false);

            bool apiIsEstablished = Reddit.ApiIsEstablished();

            if (apiIsEstablished)
            {
                await context.Reply(":white_check_mark: The connection to the Reddit API appears to be working").ConfigureAwait(false);
            }
            else
            {
                await context.Reply(":x: Error: It appears the connection to the Reddit API is not working").ConfigureAwait(false);
            }

            await checkingMessage.DeleteAsync().ConfigureAwait(false);
        }