public async Task Ganglb() { var gangs = (await GangRepository.AllAsync(Context.Guild.Id)).OrderByDescending(x => x.Wealth).ToList(); string message = "```asciidoc\n= The Wealthiest Gangs =\n"; int longest = 0; for (int i = 0; i < gangs.Count(); i++) { if (i + 1 >= Config.GANGSLB_CAP) { break; } if (gangs[i].Name.Length > longest) { longest = $"{i + 1}. {gangs[i].Name}".Length; } } for (int i = 0; i < gangs.Count(); i++) { if (i + 1 >= Config.GANGSLB_CAP) { break; } message += $"{i + 1}. {gangs[i].Name}".PadRight(longest + 2) + $" :: {gangs[i].Wealth.ToString("C", Config.CI)}\n"; } await ReplyAsync($"{message}```"); }
public Crime(UserRepository userRepo, GangRepository gangRepo, ModerationService moderationService, GameService gameService, InteractiveService interactiveService, CooldownService CooldownService) { _userRepo = userRepo; _gangRepo = gangRepo; _moderationService = moderationService; _gameService = gameService; _interactiveService = interactiveService; _cooldownService = CooldownService; }
public async Task Ganglb() { using (var db = new SQLite.Models.DbContext()) { var guildRepo = new GuildRepository(db); var gangRepo = new GangRepository(db); var gangs = gangRepo.GetAll().OrderByDescending(x => x.Wealth); string message = "```asciidoc\n= The Wealthiest Gangs =\n"; int position = 1; int longest = 0; foreach (var gang in gangs) { if (Context.Guild.Id != gang.GuildId) { continue; } if (gang.Name.Length > longest) { longest = $"{position}. {gang.Name}".Length; } if (position >= Config.GANGSLB_CAP || gangs.Last().Id == gang.Id) { break; } position++; } int positionInMessage = 1; foreach (var gang in gangs) { if (Context.Guild.Id != gang.GuildId) { continue; } message += $"{positionInMessage}. {gang.Name}".PadRight(longest + 2) + $" :: {gang.Wealth.ToString("C2")}\n"; if (positionInMessage >= Config.GANGSLB_CAP) { break; } positionInMessage++; } if ((await guildRepo.FetchGuildAsync(Context.Guild.Id)).DM) { var channel = await Context.User.CreateDMChannelAsync(); await channel.SendMessageAsync($"{message}```"); } else { await ReplyAsync($"{message}```"); } } }
public AutoIntrestRate(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _gangRepo = _serviceProvider.GetService <GangRepository>(); ObjectState StateObj = new ObjectState(); TimerCallback TimerDelegate = new TimerCallback(ApplyInterestRate); _timer = new Timer(TimerDelegate, StateObj, TimeSpan.Zero, Config.AutoInterestRateCooldown); StateObj.TimerReference = _timer; }
public async Task ResetCooldowns([Remainder] string name) { using (var db = new SQLite.Models.DbContext()) { var userRepo = new UserRepository(db); var gangRepo = new GangRepository(db); var user = await userRepo.FetchUserAsync(Context.User.Id); if (user.Cash < Config.GANG_CREATION_COST) { throw new Exception($"You do not have {Config.GANG_CREATION_COST.ToString("C2")}. Balance: {user.Cash.ToString("C2")}."); } await userRepo.EditCashAsync(Context, -Config.GANG_CREATION_COST); var gang = await gangRepo.CreateGangAsync(Context.User.Id, Context.Guild.Id, name); await ReplyAsync($"{Context.User.Mention}, You have successfully created the {gang.Name} gang!"); } }
public async Task ChangeGangName([Remainder] string name) { var user = await UserRepository.FetchUserAsync(Context); if (user.Cash < Config.GANG_NAME_CHANGE_COST) { throw new Exception($"You do not have {Config.GANG_NAME_CHANGE_COST.ToString("C", Config.CI)}. Balance: {user.Cash.ToString("C", Config.CI)}."); } if ((await GangRepository.AllAsync(Context.Guild.Id)).Any(x => x.Name == name)) { throw new Exception($"There is already a gang by the name {name}."); } await UserRepository.EditCashAsync(Context, -Config.GANG_NAME_CHANGE_COST); await GangRepository.ModifyAsync(x => { x.Name = name; return(Task.CompletedTask); }, Context.User.Id, Context.Guild.Id); await ReplyAsync($"You have successfully changed your gang name to {name} at the cost of {Config.GANG_NAME_CHANGE_COST.ToString("C", Config.CI)}."); }
public async Task KickFromGang(IGuildUser user) { using (var db = new SQLite.Models.DbContext()) { var gangRepo = new GangRepository(db); var guildRepo = new GuildRepository(db); if (!(await gangRepo.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id))) { throw new Exception("This user is not a member of your gang!"); } var gang = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id); await gangRepo.RemoveMemberAsync(user.Id, Context.Guild.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully kicked {user} from {gang.Name}"); var channel = await user.CreateDMChannelAsync(); await channel.SendMessageAsync($"You have been kicked from {gang.Name}."); } }
public async Task TransferLeadership(IGuildUser user) { if (user.Id == Context.User.Id) { throw new Exception("You are already the leader of this gang!"); } var gang = await GangRepository.FetchGangAsync(Context); if (!(await GangRepository.IsMemberOfAsync(Context.User.Id, Context.Guild.Id, user.Id))) { throw new Exception("This user is not a member of your gang!"); } await GangRepository.RemoveMemberAsync(Context.User.Id, Context.Guild.Id); await GangRepository.ModifyAsync(x => { x.LeaderId = user.Id; return(Task.CompletedTask); }, Context); await GangRepository.AddMemberAsync(Context.User.Id, Context.Guild.Id, Context.User.Id); await ReplyAsync($"{Context.User.Mention}, You have successfully transferred the leadership of {gang.Name} to {user.Mention}"); }