Guest User

TextNotifications

a guest
Jul 22nd, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.91 KB | None | 0 0
  1. AmejiOrape's Commented Source Code for TextNotifications.dll for KRelay (This isn't the whole code, this is just the main file of the plugin for beginners to understand.) The comments may be garbled because I pasted from Visual Studio.
  2.  
  3. //These are the references that your code makes. This plugin uses all of these.
  4. using Lib_K_Relay;
  5. using Lib_K_Relay.Interface;
  6. using Lib_K_Relay.Networking;
  7. using Lib_K_Relay.Networking.Packets;
  8. using Lib_K_Relay.Networking.Packets.Server;
  9. using Lib_K_Relay.Networking.Packets.Client;
  10. using Lib_K_Relay.Utilities;
  11. using System.Windows.Forms;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using Notifag; //This reference is an inside reference; it is created by a .settings file and is the needed to use NotifierConfig.Default
  15.  
  16. namespace Notifier
  17. {
  18.     public class Notifier : IPlugin //Say that the following code uses the IPlugin
  19.     {
  20.         public string GetAuthor() //The GetAuthor() string of IPlugin; it is simply your name.
  21.         {
  22.             return "Ameji";
  23.         }
  24.  
  25.         public string GetName() //The GetName() string of IPlugin; it is the name of your plugin.
  26.         {
  27.             return "Text Notifier";
  28.         }
  29.  
  30.         public string GetDescription() //The GetDescription() string of IPlugin; it is the description of your plugin.
  31.         {
  32.             return "Displays a notification when someone's chat message contains a keyword.";
  33.         }
  34.  
  35.         public string[] GetCommands() //The GetCommands() string[] of IPlugin; it is all the commands for the plugin.
  36.         {
  37.             return new string[] { "/notif on:off\n/notif words\n/notif color\n/tpto" };
  38.         }
  39.  
  40.         public void Initialize(Proxy proxy) //When the proxy starts, hook the events that will trigger specialized code.
  41.         {
  42.             proxy.HookCommand("notif", OnNotifierCommand);
  43.             proxy.HookCommand("tpto", OnTpCommand);
  44.             proxy.HookPacket(PacketType.TEXT, OnText);
  45.         }
  46.  
  47.         /* private void OnKey(Keys key)
  48.         {
  49.             Code not implemented
  50.         }
  51.         */
  52.         private void OnNotifierCommand(Client client, string command, string[] args) //When the user types /notif *
  53.         {
  54.             if (args.Length == 0) //If there is nothing after "/notif"
  55.                 return; //Cancel
  56.             if (args[0] == "words") //If the command is /notif words
  57.                 PluginUtils.ShowGUI((Form)new Form1()); //Show the form to fill in the keywords
  58.             else if (args[0] == "color") //On the otherhand, if the command is /notif color
  59.             {
  60.                 PluginUtils.ShowGUI((Form)new Form2()); //Show the form to choose a color
  61.             }
  62.             else if (args[0] == "on") //If the command is /notif on
  63.             {
  64.                 NotifierConfig.Default.Enabled = true; //Make the variable NotifierConfig.Default.Enabled true (used later)
  65.                 client.SendToClient((Packet)PluginUtils.CreateNotification(client.ObjectId, "Notifications Enabled!")); //Display a notification that the plugin is turned on.
  66.             }
  67.             else if (args[0] == "off") //I'll let you figure this one out.
  68.             {
  69.                 NotifierConfig.Default.Enabled = false;
  70.                 client.SendToClient((Packet)PluginUtils.CreateNotification(client.ObjectId, "Notifications Disabled!"));
  71.             }
  72.         }
  73.  
  74.         private void OnTpCommand(Client client, string command, string[] args) //When the user sends "/tpto"
  75.         {
  76.             if (!NotifierConfig.Default.Enabled) return; //If the plugin isn't turned on, do not do anything.
  77.             if (args.Length == 0) //Make sure it is just /tpto, nothing after it.
  78.             {
  79.                 PlayerTextPacket telePort = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT); //Create a "player text" packet named telePort
  80.                 telePort.Text = "/teleport " + NotifierConfig.Default.tp; //The text info of this packet is "/teleport " + the name of someone who triggered the notifier.
  81.                 client.SendToServer(telePort); //Send the player text packet to the server.
  82.             }
  83.         }
  84.  
  85.         private void OnText(Client client, Packet packet) //When the proxy recieves a text packet
  86.         {
  87.             if (!NotifierConfig.Default.Enabled) return; //If the plugin isn't turned on, cancel the event.
  88.             //Side note :: the ! means opposite of, so in a true/false case, !true = false; !false = true. the return; command breaks the programs eyes from this block of code (OnText() {This stuff in the brackets}) to the outside of it.
  89.             //So basically, it takes the opposite of the "Enabled" boolean, and if that is true, then the "Enabled" boolean is false, so the event is canceled.  
  90.             TextPacket textPacket = (TextPacket)packet; //Assign the textpacket to a variable
  91.             List<string> Input = textPacket.Text.Split(' ').ToList(); //Put the textpacket's text value into a list of strings, based on every space.
  92.             List<string> whiteListed = (from i in Input where NotifierConfig.Default.Whitelist.Contains(i) select i).ToList(); //Make a list of words that both the Whitelist and the textpacket have
  93.             List<string> blackListed = (from i in Input where NotifierConfig.Default.Blacklist.Contains(i) select i).ToList(); //Make a list of words that both the Blacklist and the textpacket have
  94.             if (blackListed.Count == 0 && whiteListed.Count > 0) //If the textpacket has no blacklist words and more than 0 whitelist words
  95.             {
  96.                 NotifierConfig.Default.tp = textPacket.Name; //Set the Default.tp to the name of the person who said the text.
  97.                 client.SendToClient(PluginUtils.CreateNotification(client.ObjectId, NotifierConfig.Default.NotifColor.ToArgb(), whiteListed[0] + " called!")); //Send a notification that the whitelisted word was called. Only counts the first match to prevent overlaps.
  98.             }
  99.  
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment