Guest User

Untitled

a guest
May 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3. using Discord;
  4. using Discord.WebSocket;
  5. using OctoBot.Configs;
  6.  
  7. namespace OctoBot.Handeling
  8. {
  9. public class EveryLogHandeling
  10. {
  11. private static readonly DiscordSocketClient Client = Global.Client;
  12. static readonly SocketTextChannel LogTextChannel = Global.Client.GetGuild(375104801018609665).GetTextChannel(446868049589698561);
  13.  
  14.  
  15. public static Task _client_Ready()
  16. {
  17. Client.MessageUpdated += Client_MessageUpdated;
  18. return Task.CompletedTask;
  19. }
  20.  
  21. public static async Task Client_MessageUpdated(Cacheable<IMessage, ulong> messageBefore, SocketMessage messageAfter, ISocketMessageChannel arg3)
  22. {
  23. try
  24. {
  25.  
  26. var before = (messageBefore.HasValue ? messageBefore.Value : null) as IUserMessage; // ALWAYS FALSE
  27. // messageBefore.Value.Content IS ALWAYS NULL
  28. // messageAfter is good
  29.  
  30. if (messageAfter?.Channel is IGuildChannel guildChannel)
  31. {
  32.  
  33. var textChannel = guildChannel as ITextChannel;
  34.  
  35. if (messageBefore.HasValue && messageBefore.Value.Content != messageAfter.Content && !string.IsNullOrEmpty(messageBefore.Value.Content))
  36. {
  37.  
  38. string editText = $"**{messageAfter.Author.Username}** modified in {textChannel.Mention}: `{messageBefore.Value.Content}` to `{messageAfter.Content}`";
  39. await LogTextChannel.SendMessageAsync(editText.Substring(0, Math.Min(editText.Length, Discord.DiscordConfig.MaxMessageSize)));
  40. }
  41. }
  42. }
  43. catch
  44. {
  45. Console.WriteLine($"catch upd");
  46. }
  47. }
  48.  
  49. }
  50. }
Add Comment
Please, Sign In to add comment