public async Task Donate(CommandContext ctx, uint amount, DiscordMember recipient) { SilkDbContext db = _dbFactory.CreateDbContext(); GlobalUserModel?sender = db.GlobalUsers.FirstOrDefault(u => u.Id == ctx.User.Id); GlobalUserModel?receiver = db.GlobalUsers.FirstOrDefault(u => u.Id == recipient.Id); if (sender is null && receiver is null) { await ctx.RespondAsync("Hmm. Seems like neither of you have an account here. " + $"Go ahead and do `{ctx.Prefix}daily` for me and " + "I'll give you some cash to send to your friend *:)*"); return; } if (receiver is null) { receiver = new GlobalUserModel { Id = recipient.Id }; db.GlobalUsers.Add(receiver); } if (receiver == sender) { await ctx.RespondAsync("I'd love to duplicate money just as much as the next person, but we have an economy!"); } else if (sender.Cash < amount) { await ctx.RespondAsync($"You're {amount - sender.Cash} dollars too short for that, I'm afraid."); } else if (amount >= 1000) { await VerifyTransactionAsync(ctx, sender, receiver, amount); } else { await DoTransactionAsync(ctx, amount, sender, receiver); } await db.SaveChangesAsync(); }
public async Task SetPrefix(CommandContext ctx, string prefix) { SilkDbContext db = _dbFactory.CreateDbContext(); (bool valid, string reason) = IsValidPrefix(prefix); if (!valid) { await ctx.RespondAsync(reason); return; } GuildModel guild = db.Guilds.First(g => g.Id == ctx.Guild.Id); guild.Prefix = prefix; _prefixCache.UpdatePrefix(ctx.Guild.Id, prefix); await db.SaveChangesAsync(); await ctx.RespondAsync($"Done! I'll respond to `{prefix}` from now on."); }