Exemple #1
0
        public async Task DailyAsync()
        {
            DatabaseUserEntry entry = Database.GetUserEntry(0, Context.Message.Author.Id);

            async Task giveCoins()
            {
                entry.LastDaily = DateTime.Now;
                entry.Coins    += DailyCoinAmount;
                Database.WriteData();
                await ReplyAsync($"> You have been given **{DailyCoinAmount}**, your total is now **{entry.Coins}**.");
            }

            if (entry.LastDaily == null)
            {
                await giveCoins();
            }
            else
            {
                // Assume no one waits exactly a year, even if they do its not that bad
                if (entry.LastDaily.Value.DayOfYear != DateTime.Now.DayOfYear)
                {
                    await giveCoins();
                }
                else
                {
                    await ReplyAsync($"> You have already collected your daily today, please try again tomorrow.");
                }
            }
        }
Exemple #2
0
        public async Task TransferCoinAsync(IUser target, uint amount)
        {
            if (target.IsBot)
            {
                return;
            }

            DatabaseUserEntry entry      = Database.GetUserEntry(0, Context.Message.Author.Id);
            DatabaseUserEntry targetUser = Database.GetUserEntry(0, target.Id);

            if (entry.Coins > amount)
            {
                await transferCoins();
            }
            else
            {
                await ReplyAsync($"> {Emotes.BelfastPout} You don't seem to have {amount} coins to transfer.");
            }

            async Task transferCoins()
            {
                entry.Coins      -= amount;
                targetUser.Coins += amount;
                Database.WriteData();
                await ReplyAsync($"> {Emotes.BelfastHappy} You have given **{target.Mention}** {amount} coins!");
            }
        }
Exemple #3
0
        public async Task SellCardAsync([Summary("Card rarity to sell")] string rarity, [Summary("Card name to sell")][Remainder] string cardName)
        {
            DatabaseUserEntry userData = Db.GetUserEntry(0, Context.Message.Author.Id);
            GachaCard         exits    = userData.Cards.FirstOrDefault(card => string.Equals(card.Name, cardName, StringComparison.OrdinalIgnoreCase) && string.Equals(card.Rarity.ToString(), rarity, StringComparison.OrdinalIgnoreCase));

            if (exits != null)
            {
                uint refundCoin = GetPriceForCard(exits.Rarity);

                await ReplyAsync($"> Sold **{exits.Name} [{exits.Rarity.ToString()}]** for **{refundCoin}** coins {Emotes.DiscordCoin}");

                if (exits.Amount > 1)
                {
                    exits.Amount--;
                }
                else
                {
                    if (userData.FavoriteCard == exits)
                    {
                        userData.FavoriteCard = null;
                    }
                    userData.Cards.Remove(exits);
                }
                userData.Coins += refundCoin;
                Db.WriteData();
                return;
            }
            await ReplyAsync("> Couldn't find the specified card with given name");
        }
Exemple #4
0
        public async Task GetUserGacha([Summary("(optional) The user profile to get")] IUser target = null)
        {
            target = target ?? Context.Message.Author;

            if (target.IsBot)
            {
                return;
            }

            DatabaseUserEntry userData = Db.GetUserEntry(0, target.Id);

            if (userData.Cards.Count <= 0)
            {
                await Context.Channel.SendMessageAsync($"{Emotes.BelfastShock} You don't seem to have any cards.\nTry .gao to open cards.");

                return;
            }

            string characterString = userData.Cards.Count > 0
                ? userData.Cards.Select(card => $"► **[{card.Name}](https://www.animecharactersdatabase.com/characters.php?id={card.Id})** [{card.Rarity}] x{card.Amount}").NewLineSeperatedString()
                : "**None**";

            string[] strings = characterString.NCharLimitToClosestDelimeter(512, "\n");

            await PaginatedMessageService.SendPaginatedDataMessageAsync(
                Context.Channel,
                strings,
                (result, index, footer) => GetUserGachaEmbed(target, result, footer)
                );
        }
        public async Task InitializeAsync()
        {
            if (m_client == null)
            {
                m_logger.LogWarning($"[{nameof(MessageRewardService)}] m_client is null, ignoring");
                return;
            }
            m_client.MessageReceived += async(SocketMessage msg) =>
            {
                SocketUserMessage message = msg as SocketUserMessage;
                int argPos = 0;
                if (!(message.HasStringPrefix(m_config.Configuration.Prefix, ref argPos, StringComparison.OrdinalIgnoreCase) ||
                      message.HasMentionPrefix(m_client.CurrentUser, ref argPos) ||
                      message.Author.IsBot))
                {
                    //DatabaseUserEntry userDB = m_db.GetUserEntry((message.Channel as SocketGuildChannel).Guild.Id, message.Author.Id);
                    DatabaseUserEntry userDB = m_db.GetUserEntry(0, message.Author.Id);
                    IUser             user   = message.Author;

                    userDB.Coins++;
                    uint oldLevel = userDB.Level;
                    userDB.Xp += (uint)Math.Log(message.Content.Length + 1);
                    uint newLevel = userDB.Level;

                    if (oldLevel != newLevel)
                    {
                        uint oldCoins     = userDB.Coins;
                        uint awardedCoins = (uint)Math.Pow(userDB.Level / 2f, 4f);
                        userDB.Coins += awardedCoins;

                        Embed embed = new EmbedBuilder()
                                      .WithColor(0xFF1288)
                                      .WithThumbnailUrl(Emotes.BelfastHappy.Url)
                                      .WithAuthor(author => {
                            author
                            .WithName($"Profile of {message.Author.Username}")
                            .WithIconUrl($"{message.Author.GetAvatarUrl()}");
                        })
                                      .WithTitle($"{user.Username} Leveled Up! ▲")
                                      .AddField("Details",
                                                $"► Level: **{oldLevel}** => **{userDB.Level}**\n" +
                                                $"► Coins: **{oldCoins}** => **{userDB.Coins}** {Emotes.DiscordCoin} (**+{awardedCoins}**{Emotes.DiscordCoin})")
                                      .Build();

                        m_db.WriteData();

                        //await message.Channel.SendMessageAsync(embed: embed);
                    }
                }
                await Task.CompletedTask;
            };

            await Task.CompletedTask;
        }
Exemple #6
0
        public async Task FavoriteCardAsync([Summary("Card name to favorite")][Remainder] string cardName)
        {
            DatabaseUserEntry userData = Db.GetUserEntry(0, Context.Message.Author.Id);
            GachaCard         exits    = userData.Cards.FirstOrDefault(card => string.Equals(card.Name, cardName, StringComparison.OrdinalIgnoreCase));

            if (exits != null)
            {
                userData.FavoriteCard = exits;
                await ReplyAsync($"> Set **{exits.Name}** as favorite card");

                Db.WriteData();
                return;
            }
            await ReplyAsync("> Couldn't find the specified card with given name");
        }
        public async Task WarnAsync([Summary("User that will be warned")] SocketGuildUser target,
                                    [Summary("Reason for warning the user")][Remainder] string reason = "No reason specified")
        {
            Logger.LogInfo($"Warning {target}");

            if (target.IsBot)
            {
                await ReplyAsync($"{Context.User.Mention} You cannot warn a bot");

                return;
            }

            if (target == Context.User)
            {
                await ReplyAsync($"{Context.User.Mention} You cannot warn yourself");

                return;
            }

            bool isHigherRole = IsBotHigherRoleThan(target);

            if (isHigherRole)
            {
                DatabaseUserEntry user = Db.GetUserEntry(target.Guild.Id, target.Id);

                user.Warns.Add(new Warn(reason, Context.User.Id));
                Db.WriteData();
                IDMChannel dm = await target.GetOrCreateDMChannelAsync();

                await dm.SendMessageAsync($"You have been warned on {Context.Guild.Name} for {reason}");
                await ReplyAsync($"Warned {target.Mention} for \"{reason}\"");

                if (user.Warns.Count == 2)
                {
                    await KickUserAsync(target, reason);
                }
                else if (user.Warns.Count >= Config.Configuration.MaxWarnAmount)
                {
                    await BanUserAsync(target, reason);
                }
            }
            else
            {
                await ReplyAsync($"Can't warn {target.Mention} with higher role than me");
            }
        }
Exemple #8
0
        public async Task CheckProfileAsync([Summary("(optional) The user profile to get")] IUser target = null)
        {
            target = target ?? Context.Message.Author;

            if (target.IsBot)
            {
                return;
            }

            DatabaseUserEntry userData = Db.GetUserEntry(0, target.Id);

            string warns = "NaN";

            if (Context.Guild != null)
            {
                DatabaseUserEntry serverUserData = Db.GetUserEntry(Context.Guild.Id, target.Id);
                warns = serverUserData.Warns.Count.ToString();
            }

            Embed embed = new EmbedBuilder()
                          .WithColor(0xF5CD63)
                          .WithAuthor(author => {
                author
                .WithName($"Profile of {target.Username}")
                .WithIconUrl($"{target.GetAvatarUrl()}");
            })
                          .AddField("Details ▼",
                                    $"__**Status In Current Server**__\n" +
                                    $"► Warn Amount: **{warns}**/{Config.Configuration.MaxWarnAmount}\n" +
                                    $"__**Profile**__\n" +
                                    $"► Level: **{userData.Level}** [**{userData.Xp}**] \n" +
                                    $"► Coins: **{userData.Coins}** {Emotes.DiscordCoin}\n" +
                                    $"► Gacha Rolls: **{userData.GachaRolls}**\n" +
                                    $"► Card Amount: **{userData.Cards.Count}**\n" +
                                    $"► Favorite Card: **{(userData.FavoriteCard != null ? $"[{userData.FavoriteCard.Name}](https://www.animecharactersdatabase.com/characters.php?id={userData.FavoriteCard.Id})" : "None")}**")
                          .WithFooter(footer => {
                footer
                .WithText($"Requested by {Context.User}")
                .WithIconUrl(Context.User.GetAvatarUrl());
            })
                          .WithThumbnailUrl($"{target.GetAvatarUrl()}")
                          .Build();

            await ReplyAsync(embed : embed);
        }
        public async Task DeleteWarningAsync([Summary("User who's warning will be deleted")] SocketGuildUser target, int index)
        {
            Logger.LogInfo($"Deleting warning number {index} from {target}");

            int proIndex = index - 1;

            DatabaseUserEntry user = Db.GetUserEntry(target.Guild.Id, target.Id);

            if (proIndex > user.Warns.Count || proIndex < 0)
            {
                await ReplyAsync($"Out of bounds, user has {user.Warns.Count} warnings");

                return;
            }

            user.Warns.RemoveAt(proIndex);
            Db.WriteData();

            await ReplyAsync($"Deleted warning number {index} from {target.Mention}");
        }
        public async Task WarningsAsync([Summary("User who's warnings will be displayed")] SocketGuildUser target = null)
        {
            Logger.LogInfo($"Showing {target}'s warnings)");

            target = target ?? Context.User as SocketGuildUser;
            if (target == null)
            {
                await ReplyAsync("Couldn't find a user to target");

                return;
            }

            DatabaseUserEntry user = Db.GetUserEntry(target.Guild.Id, target.Id);

            EmbedFieldBuilder builder = new EmbedFieldBuilder()
                                        .WithName($"{target}'s Warnings");

            string value = string.Empty;

            int i = 1;

            foreach (Warn warn in user.Warns)
            {
                value += $"{i}. {warn.Reason}\n";
                i++;
            }

            if (string.IsNullOrEmpty(value))
            {
                value = "No warnings";
            }

            builder.WithValue(value);

            Embed embed = new EmbedBuilder()
                          .WithColor(0xf09e24)
                          .WithFields(builder)
                          .Build();

            await ReplyAsync(embed : embed);
        }
Exemple #11
0
        public async Task GetGacha([Summary("Card pack index")][Remainder] int cardPack = 1)
        {
            if (!Config.Configuration.Packs.TryGetValue(cardPack, out string content))
            {
                await ReplyAsync("> Invalid Card Pack");

                return;
            }

            DatabaseUserEntry userData = Db.GetUserEntry(0, Context.Message.Author.Id);

            if (userData.Coins < Config.Configuration.GachaPrice)
            {
                await ReplyAsync($"> Insufficient Coins {Emotes.DiscordCoin}");

                return;
            }

            AnimeCharacterDatabaseApi.AnimeResult anime = await AnimeCharacterDatabaseApi.Client.SearchAnimeAsync(content);

            AnimeCharacterDatabaseApi.CharacterResult result = await AnimeCharacterDatabaseApi.Client.GetCharactersAsync(anime.Id);

            userData.Coins -= Config.Configuration.GachaPrice;
            userData.GachaRolls++;

            m_random = new Random(DateTime.Now.Millisecond);
            float rarityLevel = (float)m_random.NextDouble();

            GachaCard newCard = new GachaCard {
                Name = result.Name, Id = result.Id, Amount = 1
            };

            newCard.Rarity = newCard.Rarity.ToPercent(rarityLevel);

            GachaCard existingCard = userData.Cards.SingleOrDefault(card => card.Id == result.Id && card.Rarity == newCard.Rarity);

            if (existingCard != null)
            {
                existingCard.Amount++;
            }
            else
            {
                userData.Cards.Add(newCard);
            }

            Db.WriteData();

            Embed embed = new EmbedBuilder()
                          .WithColor(GetColorForCard(newCard.Rarity))
                          .WithAuthor(author => {
                author
                .WithName($"Opened {anime.Name} Card Pack! 🎉")
                .WithUrl($"https://www.animecharactersdatabase.com/characters.php?id={result.Id}");
            })
                          .WithThumbnailUrl(anime.Image)
                          .AddField($"Details",
                                    $"► Rarity: **{newCard.Rarity}**\n" +
                                    $"► Name: **{result.Name}**\n" +
                                    $"► Gender: **{result.Gender}**\n" +
                                    $"► From: **{anime.Name}**\n" +
                                    $"{result.Name} has been added to you cards list!")
                          .WithImageUrl(result.ImageUrl)
                          .WithFooter(footer => {
                footer
                .WithText($"Paid {Config.Configuration.GachaPrice} coins for a roll")
                .WithIconUrl(Context.User.GetAvatarUrl());
            })
                          .Build();

            await ReplyAsync(embed : embed);
        }