public async Task WriteMessage(ISocketMessageChannel channel, IUserMessage message, EventsWithCount @event) { var messageContents = $"**Confirmation Check for {@event.Name}!{Environment.NewLine}" + $"Please confirm your attendance by reacting to this message.**{Environment.NewLine}{Environment.NewLine}"; if ([email protected] && [email protected]) { messageContents += $"You can still sign up to this event by typing `!event join {@event.DisplayName}`{Environment.NewLine}{Environment.NewLine}"; } var signUps = await _eventSignups.GetAllSignupsForEvent(@event); var confirmed = new List <IUser>(); foreach (var reaction in message.Reactions) { var reactors = await message.GetReactionUsersAsync(reaction.Key, 999).FlattenAsync(); confirmed.AddRange(reactors); } confirmed = confirmed.Distinct(new UserEqualityComparer()).Where(confirmed => signUps.Any(sup => sup.UserId == confirmed.Id.ToString())).ToList(); var unconfirmed = signUps.Where(signUp => !confirmed.Any(con => con.Id.ToString() == signUp.UserId)); var channelUsers = await channel.GetUsersAsync().FlattenAsync(); var unconfirmedUsers = unconfirmed.Select(u => channelUsers.FirstOrDefault(cu => cu.Id.ToString() == u.UserId)).ToList(); messageContents += $"**Confirmed:**{Environment.NewLine}" + $"{string.Join(Environment.NewLine, confirmed.Select(con => con?.Mention ?? "Unknown User"))}{Environment.NewLine}"; messageContents += $"**Unconfirmed:**{Environment.NewLine}" + $"{string.Join(Environment.NewLine, unconfirmedUsers.Select(con => con?.Mention ?? "Unknown User"))}{Environment.NewLine}"; await message.ModifyAsync((msg) => msg.Content = messageContents); }
public static List <SocketGuildUser> GetUsers(this ISocketMessageChannel channel) { var users = new List <SocketGuildUser>(); channel.GetUsersAsync().ForEachAsync(u => users.AddRange(u.Cast <SocketGuildUser>())); return(users); }
/// <summary> /// An ection that represents a Discrod Latency check (Heartbeat) /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> /// <returns></returns> public async Task ClientLatencyUpdated(int arg1, int arg2) { // If the client is ready and the current time exceeds the update timer if (Instance.Ready) { #region Delete commands messages and reponses // THe channel to write a message in ISocketMessageChannel channel = Client.GetChannel(ulong.Parse(GeneralChannelID)) as ISocketMessageChannel; if (this.deleteOldMessages.ReadyToUpdate()) { Debug.Log.Message("DiscordHandler - Deleting messages"); // Loop trough the last 100 cached messages and delete them if it was a command or if Sonnie wrote them foreach (var message in await channel.GetMessagesAsync().FlattenAsync()) { if (message.Author.Username == Client.CurrentUser.Username || message.Content [0] == ';') { //Debug.Log.Message ( $"Auther: {message.Author.Username} | Content: {message.Content}" ); await message.DeleteAsync(); } } } #endregion #region Checking vacation state // Tell people in the discord that Sonnie is no longer in vacation mode. if (!Vacation.OnVecation() && Vacation.WasOnVacation) { Debug.Log.Message("Returned from vac"); await channel.SendMessageAsync("Jeg er tilbage fra ferie!"); Vacation = Vacation.SetInvalidVacation(); Vacation.WasOnVacation = false; System.DataScanner <Vacation> vacScanner = new System.DataScanner <Vacation> (@"\Data\Events\STB.VP"); await vacScanner.WriteToFile(string.Empty); } // To track if Sonnie was on vacation mode recently. if (Vacation.OnVecation() && !Vacation.WasOnVacation) { Debug.Log.Message("Going into vac"); await channel.SendMessageAsync("Jeg går på ferie nu!"); Vacation.WasOnVacation = true; } if (!Vacation.OnVecation() && Instance.checkForPornoUpdateTimer.ReadyToUpdate()) { foreach (var guildUser in Client.GetGuild(614042459957362698).Users) { await CheckForPorno(guildUser, channel); } } #endregion #region Checking if there's an event that should be prompted // Check if there's any upcomming events foreach (Event item in EventManager.Events) { DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0); Debug.Log.Message($"DiscordHandler - Comparing {item.Prompt.TimeOfDay} to {today.TimeOfDay}"); // If an events prompt time is now, remind the users about the event if (item.Prompt.Date == today.Date && item.Prompt.TimeOfDay == today.TimeOfDay) { Debug.Log.Message("DiscordHandler - Duo time: Promping users"); // Send a message to each user in the channel foreach (IGuildUser user in await channel.GetUsersAsync().FlattenAsync()) { if (!user.IsBot) { IDMChannel dmChannel = await user.GetOrCreateDMChannelAsync(); // Only try to send if a DM channel can be established if (dmChannel != null) { Debug.Log.Message($"DiscordHandler - Sending to: {user.Username}"); _ = dmChannel.SendMessageAsync($"Påmindelse omkring event:{Environment.NewLine}{item.Print ()}"); } } } } } #endregion #region Update Facebook log // Check for new Feacebook posts if (Instance.facebookUpdateTimer.ReadyToUpdate()) { Debug.Log.Message("DiscordHandler - Updating Facebook-Feed"); FacebookHandler.Instance.SendHTTPRequest().GetAwaiter().GetResult(); await FacebookHandler.Instance.PostLastFacebookPost(Client); } #endregion } }