Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModeratorCommands.cs 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using ExitGames.Client.Photon.Chat;
  5. namespace CLre_server.Tweaks.Chat
  6. {
  7. public static class ModeratorCommands
  8. {
  9. [ChatCommand("KICK", "kick ([\\w\\d\\-_]+)")]
  10. public static void KickInButt(Match messageMatch, ChatClient connection, string sender)
  11. {
  12. if (!API.MainServer.Moderator.Instance.IsModerator(sender))
  13. {
  14. connection.PublishMessage(ChatListener.ChatName, "Ban failure: You're not a mod :(");
  15. return;
  16. }
  17. string target = messageMatch.Groups[1].Value;
  18. #if DEBUG
  19. API.Utility.Logging.MetaLog($"/kick {target}");
  20. #endif
  21. if (API.MainServer.Moderator.Instance.DisconnectPlayerById(target))
  22. {
  23. connection.PublishMessage(ChatListener.ChatName, $"Adios {target}");
  24. }
  25. else if (API.MainServer.Moderator.Instance.DisconnectPlayerByName(target))
  26. {
  27. connection.PublishMessage(ChatListener.ChatName, $"Bye bye {target}");
  28. }
  29. else
  30. {
  31. connection.PublishMessage(ChatListener.ChatName, "Kick failure: User not found :(");
  32. }
  33. }
  34. [ChatCommand("BAN", "ban ([\\w\\d\\-_]+)")]
  35. public static void BanishIdiot(Match messageMatch, ChatClient connection, string sender)
  36. {
  37. if (!API.MainServer.Moderator.Instance.IsModerator(sender))
  38. {
  39. connection.PublishMessage(ChatListener.ChatName, "Ban failure: You're not a mod :(");
  40. return;
  41. }
  42. string target = messageMatch.Groups[1].Value;
  43. #if DEBUG
  44. API.Utility.Logging.MetaLog($"/ban {target}");
  45. #endif
  46. if (API.MainServer.Moderator.Instance.BanPlayerById(target))
  47. {
  48. connection.PublishMessage(ChatListener.ChatName, $"And {target} is no more!");
  49. }
  50. else if (API.MainServer.Moderator.Instance.BanPlayerByName(target))
  51. {
  52. connection.PublishMessage(ChatListener.ChatName, $"And {target} was never seen again...");
  53. }
  54. else
  55. {
  56. connection.PublishMessage(ChatListener.ChatName, "Ban failure: User not found :(");
  57. }
  58. }
  59. [ChatCommand("(SH)OPIFY", "(mod|op) ([\\w\\d\\-_]+)")]
  60. public static void GoPro(Match messageMatch, ChatClient connection, string sender)
  61. {
  62. if (!API.MainServer.Moderator.Instance.IsModerator(sender))
  63. {
  64. connection.PublishMessage(ChatListener.ChatName, "Op failure: You're not a mod :(");
  65. return;
  66. }
  67. string target = messageMatch.Groups[2].Value;
  68. #if DEBUG
  69. API.Utility.Logging.MetaLog($"/op {target}");
  70. #endif
  71. List<string> moderators = new List<string>(CLre.Config.moderators);
  72. moderators.Add(target);
  73. CLre.Config.moderators = moderators.ToArray();
  74. connection.PublishMessage(ChatListener.ChatName, $"Promoted {target} to moderator");
  75. }
  76. [ChatCommand("De(SH)OPIFY", "(demod|deop) ([\\w\\d\\-_]+)")]
  77. public static void AntiProton(Match messageMatch, ChatClient connection, string sender)
  78. {
  79. if (!API.MainServer.Moderator.Instance.IsModerator(sender))
  80. {
  81. connection.PublishMessage(ChatListener.ChatName, "DeOp failure: You're not a mod :(");
  82. return;
  83. }
  84. string target = messageMatch.Groups[2].Value;
  85. #if DEBUG
  86. API.Utility.Logging.MetaLog($"/deop {target}");
  87. #endif
  88. List<string> moderators = new List<string>(CLre.Config.moderators);
  89. if (moderators.Remove(target))
  90. {
  91. CLre.Config.moderators = moderators.ToArray();
  92. connection.PublishMessage(ChatListener.ChatName, $"Demoted {target} to regular user");
  93. }
  94. connection.PublishMessage(ChatListener.ChatName, "DeOp failure: User not found :(");
  95. }
  96. [ChatCommand("ECHO", "echo (.+)$")]
  97. public static void EchoEchoEcho(Match messageMatch, ChatClient connection, string sender)
  98. {
  99. string target = messageMatch.Groups[1].Value;
  100. #if DEBUG
  101. API.Utility.Logging.MetaLog($"/echo {target}");
  102. #endif
  103. connection.PublishMessage(ChatListener.ChatName, target);
  104. }
  105. }
  106. }