public async Task Banroyale([Remainder] string str = "") { var banroyale = await BanroyaleDb.GetBanroyale(Context.Channel.Id); if (banroyale == null) { await Context.Channel.SendMessageAsync($"There is no running Ban Royale in this channel. `{Program.GetPrefix(Context)}nbrl` to start a new one."); return; } var reqRole = Context.Guild.GetRole(banroyale.RoleReqId); var role = Context.Guild.GetRole(banroyale.ParticipantRoleId); var users = role.Members.ToList(); string participants = users.Count > 0 ? $"\n\nParticipants:\n{BanroyaleUtil.BanroyaleParticipants(users.Select(x => x.Username).ToList())}" : ""; await Context.Channel.SendMessageAsync(embed : BanroyaleUtil.BanroyaleDetailsEmbed(banroyale, Context.Guild.GetRole(banroyale.ParticipantRoleId), Context.Guild.GetRole(banroyale.RoleReqId), users.Count).Build()); }
public async Task JoinBanroyale([Remainder] string str = "") { var user = Context.User as SocketGuildUser; var banroyale = await BanroyaleDb.GetBanroyale(Context.Channel.Id); if (banroyale == null) { await Context.Channel.SendMessageAsync(":x: There is no running Ban Royale in this channel."); return; } if (banroyale.Running == true) { await Context.Channel.SendMessageAsync(":x: The ban royale already started. You're late to the party."); return; } if (banroyale.RoleReqId != 0) { if (!user.Roles.Any(x => x.Id == banroyale.RoleReqId)) { await Context.Channel.SendMessageAsync(":x: You do not have the required role to join!"); return; } } var role = Context.Guild.GetRole(banroyale.ParticipantRoleId); var users = role.Members.ToList(); if (users.Count >= banroyale.MaxParticipants - 1 && banroyale.MaxParticipants != 0) { await Context.Channel.SendMessageAsync("Ban Royale is full!"); return; } if (users.Contains(user)) { await Context.Channel.SendMessageAsync("You are already participating! Eager to get smoked, aren't you?"); return; } await user.AddRoleAsync(role); users.Add(user); string response = "You joined the Ban Royale. *Heh.*" + (users.Count > 10 ? "" : "\n\nList of Participants:\n" + BanroyaleUtil.BanroyaleParticipants(users.Select(x => x.Username).ToList())); await Context.Channel.SendMessageAsync(response); }
public async Task NewBanroyale([Remainder] string roleName = "") { var banroyale = await BanroyaleDb.GetBanroyale(Context.Channel.Id); if (banroyale != null) { await Context.Channel.SendMessageAsync($":x: There is already a running Ban Royale in this channel. Type `{Program.GetPrefix(Context)}cbrl` to cancel it."); return; } SocketRole role = null; if (roleName != "") { role = await this.SelectRole(roleName); if (role == null) { return; } } var roleId = await BanroyaleDb.GetRoleId(Context.Guild.Id); if (roleId != 0) { try { roleId = Context.Guild.GetRole(roleId).Id; } catch { roleId = 0; } } if (roleId == 0) { var newRole = await Context.Guild.CreateRoleAsync("Namiko-Banroyale", null, Color.Red, false, false, null); roleId = newRole.Id; await ReplyAsync($"Creating a role - {newRole.Mention}. It will be used to track the Ban Royale participants automatically by assigning/removing the role to/from them.\n" + $"You can change the name and the color of the role. But make sure it is lower in the role list than my bot role, Senpai."); } banroyale = new Banroyale { Active = true, BanLengthHours = 0, ChannelId = Context.Channel.Id, MaxParticipants = 0, MinParticipants = 0, RewardPool = 0, GuildId = Context.Guild.Id, RoleReqId = role == null ? 0 : role.Id, Kick = false, WinnerAmount = 1, ParticipantRoleId = roleId, MinFrequency = 10, MaxFrequency = 20 }; string prefix = Program.GetPrefix(Context); await BanroyaleDb.AddBanroyale(banroyale); await Context.Channel.SendMessageAsync("Setting up a new game of Ban Royale! It's on." + $"\n\n**More settings:**" + $"\n`{prefix}sbrlrp` - set reward pool" + $"\n`{prefix}sbrlw` - set amount of winners" + $"\n`{prefix}sbrlminp` - minimum participants" + $"\n`{prefix}sbrlmaxp` - maximum participants" + $"\n`{prefix}sbrlban` - set loser ban duration" + $"\n`{prefix}sbrlkick` - set loser kick" + $"\n`{prefix}sbrlminf` - set min message frequency in seconds" + $"\n`{prefix}sbrlmaxf` - set max message frequency in seconds" + $"\n\n*Type `{prefix}jbrl` to join the game.*" + $"\n*Type `{prefix}startbrl` to start the game after some players join.*" + $"\n*Type `{prefix}brl` to view current settings.*", embed : BanroyaleUtil.BanroyaleDetailsEmbed(banroyale, Context.Guild.GetRole(banroyale.ParticipantRoleId), Context.Guild.GetRole(banroyale.RoleReqId)).Build()); }
private async void Timer_SendNextMessageEvent(object sender, ElapsedEventArgs e) { if (Waiting) { if (KickLast > 0) { BanroyaleMessageDict.Remove(this.Message.Id); } var usersReac = (await Message.GetReactionUsersAsync(Emote, 100).FlattenAsync()).Select(x => x.Id).ToHashSet(); var users = Role.Members.Where(x => !usersReac.Contains(x.Id)).ToList(); BanroyaleMessageDict.Remove(this.Message.Id); Waiting = false; if (await LostUsers(this, users)) { return; } } var rnd = new Random(); int x = rnd.Next(3); KickLast = Role.Members.Count(); if (KickLast > 20) { KickLast = KickLast / 10 + x; } else if (KickLast > 5) { KickLast = x; } else { KickLast = x - 1 >= 0 ? x - 1 : 0; } int emoteCount = 4; var emotes = BanroyaleUtil.DrawEmotes(emoteCount); int r = rnd.Next(emoteCount); Emote = emotes[r]; Message = await Channel.SendMessageAsync($"{Role.Mention}", embed : new EmbedBuilderPrepared($"Click the {Emote} reaction to stay in the game!\n" + $"{(KickLast > 0 ? $"Last **{KickLast}** participants to react will lose!" : "")}") .WithColor(Color.Blue) .Build()); foreach (var emote in emotes) { _ = Message.AddReactionAsync(emote); } await BanroyaleMessageDb.AddMessage(new BanroyaleMessage { Active = true, BanroyaleId = Banroyale.Id, MessageId = Message.Id, EmoteId = Emote.Id }); if (KickLast > 0) { BanroyaleMessageDict.Add(Message.Id, this); } Waiting = true; double interval = new Random().Next(Banroyale.MaxFrequency - Banroyale.MinFrequency) + Banroyale.MinFrequency; Timer.Interval = interval * 1000; Timer.Start(); }