Exemple #1
0
        public async Task GuildBankBalance(CommandContext e, MikiDbContext context, GuildUser c)
        {
            var account = await BankAccount.GetAsync(context, e.Author.Id, e.Guild.Id);

            await e.CreateEmbedBuilder()
            .WithTitle(new LanguageResource("guildbank_title", e.Guild.Name))
            .WithColor(new Color(255, 255, 255))
            .WithThumbnailUrl("https://imgur.com/KXtwIWs.png")
            .AddField(
                new LanguageResource("guildbank_balance_title"),
                new LanguageResource("guildbank_balance", c.Currency.ToFormattedString()),
                true
                )
            .AddField(
                new LanguageResource("guildbank_contributed", "{0}"), new StringResource(account.TotalDeposited.ToFormattedString())
                ).Build().QueueToChannelAsync(e.Channel);
        }
        public static async Task <Achievement> GetAchievementAsync(MikiDbContext context, long userId, string name)
        {
            string key = $"achievement:{userId}:{name}";

            var cache = MikiApp.Instance.GetService <ICacheClient>();

            Achievement a = await cache.GetAsync <Achievement>(key);

            if (a != null)
            {
                return(context.Attach(a).Entity);
            }

            Achievement achievement = await context.Achievements.FindAsync(userId, name);

            await cache.UpsertAsync(key, achievement);

            return(achievement);
        }
Exemple #3
0
        public static async Task AddAsync(MikiDbContext context, string id, string text, long creator)
        {
            if (Regex.IsMatch(text, "(http[s]://)?((discord.gg)|(discordapp.com/invite))/([A-Za-z0-9]+)", RegexOptions.IgnoreCase))
            {
                throw new Exception("You can't add discord invites!");
            }

            GlobalPasta pasta = await context.Pastas.FindAsync(id);

            if (pasta != null)
            {
                throw new DuplicatePastaException(pasta);
            }

            await context.Pastas.AddAsync(new GlobalPasta()
            {
                Id        = id,
                Text      = text,
                CreatorId = creator,
                CreatedAt = DateTime.Now
            });
        }
Exemple #4
0
        public async Task GuildBankDepositAsync(CommandContext e, MikiDbContext context, GuildUser c)
        {
            if (!e.Arguments.Take(out int totalDeposited))
            {
                // TODO: No mekos deposit error
                return;
            }

            User user = await User.GetAsync(context, e.Author.Id, e.Author.Username);

            user.RemoveCurrency(totalDeposited);
            c.Currency += totalDeposited;

            BankAccount account = await BankAccount.GetAsync(context, e.Author.Id, e.Guild.Id);

            account.Deposit(totalDeposited);

            await new EmbedBuilder()
            .SetAuthor("Guild bank", "https://imgur.com/KXtwIWs.png")
            .SetDescription(e.Locale.GetString("guildbank_deposit_title", e.Author.Username, totalDeposited.ToFormattedString()))
            .SetColor(new Color(255, 255, 255))
            .ToEmbed().QueueToChannelAsync(e.Channel);
        }
 public static async Task <User> GetUserAsync(MikiDbContext context, IDiscordUser discordUser)
 => await User.GetAsync(context, (long)discordUser.Id, discordUser.Username);
Exemple #6
0
        public static async Task SyncAvatarAsync(IDiscordUser user, IExtendedCacheClient cache, MikiDbContext context)
        {
            PutObjectRequest request = new PutObjectRequest();

            request.BucketName  = "miki-cdn";
            request.Key         = $"avatars/{user.Id}.png";
            request.ContentType = "image/png";
            request.CannedACL   = new S3CannedACL("public-read");

            string avatarUrl = user.GetAvatarUrl();

            using (var client = new Rest.RestClient(avatarUrl, true))
            {
                request.InputStream = await client.GetStreamAsync();
            }

            var response = await Global.CdnClient.PutObjectAsync(request);

            if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new AvatarSyncException();
            }

            await MikiApp.Instance.GetService <BunnyCDNClient>()
            .PurgeCacheAsync($"https://mikido.b-cdn.net/avatars/{user.Id}.png");

            User u = await User.GetAsync(context, user.Id, user.Username);

            await cache.HashUpsertAsync("avtr:sync", user.Id.ToString(), 1);

            u.AvatarUrl = u.Id.ToString();
            await context.SaveChangesAsync();
        }