public static async Task UnlockTrophyAsync(this SQLiteDatabase database, ICreator creator, ITrophy trophy)
        {
            if (creator.UserId.HasValue)
            {
                using (SQLiteCommand cmd = new SQLiteCommand("INSERT OR IGNORE INTO Trophies(user_id, trophy_name, timestamp) VALUES($user_id, $trophy_name, $timestamp);")) {
                    cmd.Parameters.AddWithValue("$user_id", creator.UserId);
                    cmd.Parameters.AddWithValue("$trophy_name", trophy.Identifier);
                    cmd.Parameters.AddWithValue("$timestamp", DateUtilities.GetCurrentTimestampUtc());

                    await database.ExecuteNonQueryAsync(cmd);
                }
            }
        }
예제 #2
0
        public async Task Gotchi()
        {
            // Get this user's primary Gotchi.

            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (!await this.ReplyValidateGotchiAsync(gotchi))
            {
                return;
            }

            // Create the gotchi GIF.

            string gifUrl = await this.ReplyUploadGotchiGifAsync(gotchi);

            if (string.IsNullOrEmpty(gifUrl))
            {
                return;
            }

            // Get the gotchi's species.

            ISpecies species = await Db.GetSpeciesAsync(gotchi.SpeciesId);

            // Pick status text.

            string status = "{0} is feeling happy!";

            switch (gotchi.State)
            {
            case GotchiState.Dead:
                status = "Oh no... {0} has died...";
                break;

            case GotchiState.Evolved:
                status = "Congratulations, {0} " + string.Format("evolved into {0}!", species.GetShortName());
                break;

            case GotchiState.Sleeping:
                long hours_left = gotchi.HoursOfSleepLeft();
                status = "{0} is taking a nap. " + string.Format("Check back in {0} hour{1}.", hours_left, hours_left > 1 ? "s" : string.Empty);
                break;

            case GotchiState.Hungry:
                status = "{0} is feeling hungry!";
                break;

            case GotchiState.Eating:
                status = "{0} is enjoying some delicious Suka-Flakes™!";
                break;

            case GotchiState.Energetic:
                status = "{0} is feeling rowdy!";
                break;

            case GotchiState.Tired:
                status = "{0} is getting a bit sleepy...";
                break;
            }

            // Update the viewed timestamp.

            await Db.SetViewedTimestampAsync(gotchi, DateUtilities.GetCurrentTimestampUtc());

            // Send the message.

            EmbedBuilder embed = new EmbedBuilder();

            embed.WithTitle(string.Format("{0}'s \"{1}\"", Context.User.Username, gotchi.Name.ToTitle()));
            embed.WithDescription(string.Format("{0}, age {1}", species.GetShortName(), gotchi.Age));
            embed.WithImageUrl(gifUrl);
            embed.WithFooter(string.Format(status, StringUtilities.ToTitleCase(gotchi.Name)));

            await ReplyAsync(embed : embed.Build());
        }