private static async Task ReactionRemovedAsync(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { var dbRole = GetRoleFromReaction(reaction); if (dbRole == null) { if (reaction.MessageId == _lastBotTenManMessageId) { var user = _guild.GetUser(reaction.UserId); UpdateMatchList(user, false); } return; } if (reaction.Emote.Name == dbRole.Emoji) { if (!string.IsNullOrEmpty(dbRole.RoleId)) { await RoleAssigner.RemoveRoleAsync(reaction.UserId, ulong.Parse(dbRole.RoleId)) .ConfigureAwait(true); } if (!string.IsNullOrEmpty(dbRole.RemovalRoleId)) { await RoleAssigner.AssignRoleAsync(reaction.UserId, ulong.Parse(dbRole.RemovalRoleId)) .ConfigureAwait(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(); }
private static Task UserJoinedAsync(SocketGuildUser user) { DownloadUsers(); return(RoleAssigner.AssignRoleAsync(user.Id, VisitorRoleId)); }