Make sure all your whitelist and blacklist words are lowercase, because now the textpacket will be converted to lower case
Just an update for my plugin for KRelay. Fixed some bugs and added some features.
The downloadable zip includes an autohotkey script so that you can press a key to tp to the caller. Just edit the script and where the big all caps words are just edit them, you should understand.
I'm also adding the source code of the main file for beginners to understand, because KRelay is a great platform and everyone should be developing plugins for it.
Source Code
Code:
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.
//These are the references that your code makes. This plugin uses all of these.
using Lib_K_Relay;
using Lib_K_Relay.Interface;
using Lib_K_Relay.Networking;
using Lib_K_Relay.Networking.Packets;
using Lib_K_Relay.Networking.Packets.Server;
using Lib_K_Relay.Networking.Packets.Client;
using Lib_K_Relay.Utilities;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using Notifag; //This reference is an inside reference; it is created by a .settings file and is the needed to use NotifierConfig.Default
namespace Notifier
{
public class Notifier : IPlugin //Say that the following code uses the IPlugin
{
public string GetAuthor() //The GetAuthor() string of IPlugin; it is simply your name.
{
return "Ameji";
}
public string GetName() //The GetName() string of IPlugin; it is the name of your plugin.
{
return "Text Notifier";
}
public string GetDescription() //The GetDescription() string of IPlugin; it is the description of your plugin.
{
return "Displays a notification when someone's chat message contains a keyword.";
}
public string[] GetCommands() //The GetCommands() string[] of IPlugin; it is all the commands for the plugin.
{
return new string[] { "/notif on:off\n/notif words\n/notif color\n/tpto" };
}
public void Initialize(Proxy proxy) //When the proxy starts, hook the events that will trigger specialized code.
{
proxy.HookCommand("notif", OnNotifierCommand);
proxy.HookCommand("tpto", OnTpCommand);
proxy.HookPacket(PacketType.TEXT, OnText);
}
private void OnNotifierCommand(Client client, string command, string[] args) //When the user types /notif *
{
if (args.Length == 0) //If there is nothing after "/notif"
return; //Cancel
if (args[0] == "words") //If the command is /notif words
PluginUtils.ShowGUI((Form)new Form1()); //Show the form to fill in the keywords
else if (args[0] == "color") //On the otherhand, if the command is /notif color
{
PluginUtils.ShowGUI((Form)new Form2()); //Show the form to choose a color
}
else if (args[0] == "on") //If the command is /notif on
{
NotifierConfig.Default.Enabled = true; //Make the variable NotifierConfig.Default.Enabled true (used later)
client.SendToClient((Packet)PluginUtils.CreateNotification(client.ObjectId, "Notifications Enabled!")); //Display a notification that the plugin is turned on.
}
else if (args[0] == "off") //I'll let you figure this one out.
{
NotifierConfig.Default.Enabled = false;
client.SendToClient((Packet)PluginUtils.CreateNotification(client.ObjectId, "Notifications Disabled!"));
}
}
private void OnTpCommand(Client client, string command, string[] args) //When the user sends "/tpto"
{
if (!NotifierConfig.Default.Enabled) return; //If the plugin isn't turned on, do not do anything.
if (args.Length == 0) //Make sure it is just /tpto, nothing after it.
{
PlayerTextPacket telePort = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT); //Create a "player text" packet named telePort
telePort.Text = "/teleport " + NotifierConfig.Default.tp; //The text info of this packet is "/teleport " + the name of someone who triggered the notifier.
client.SendToServer(telePort); //Send the player text packet to the server.
}
}
private void OnText(Client client, Packet packet) //When the proxy recieves a text packet
{
if (!NotifierConfig.Default.Enabled) return; //If the plugin isn't turned on, cancel the event.
//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.
//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.
TextPacket textPacket = (TextPacket)packet; //Assign the textpacket to a variable
List<string> Input = textPacket.Text.Split(' ').ToList(); //Put the textpacket's text value into a list of strings, based on every space.
List<string> whiteListed = (from i in Input where NotifierConfig.Default.Whitelis*****ntains(i) select i).ToList(); //Make a list of words that both the Whitelist and the textpacket have
List<string> blackListed = (from i in Input where NotifierConfig.Default.Blacklis*****ntains(i) select i).ToList(); //Make a list of words that both the Blacklist and the textpacket have
if (blackListed.Count == 0 && whiteListed.Count > 0) //If the textpacket has no blacklist words and more than 0 whitelist words
{
NotifierConfig.Default.tp = textPacket.Name; //Set the Default.tp to the name of the person who said the text.
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.
}
}
}
}
**IMPORTANT**
This plugin interferes with the autotrade bot by Jex (don't remeber his exact username) so if you are going to use it take this plugin out
Not going to use this, but it's a really useful thing, thanks for sharing! :3
Approved
I dont really plan on using this but im sure some people will!
It's a great release
would it be possible for it to play a sound?
Originally Posted by colson
would it be possible for it to play a sound?
Aha, smart one. When I first came up with this plugin I wanted it to play a sound but it seems like you can only make it play sound files on your computer. I could do it, but for the effort, so many people would fail the installation that it's not worth.
Cool ima try it
Thank you works perfect I myself have made many scripts for K relay
Originally Posted by AmejiOrape
Aha, smart one. When I first came up with this plugin I wanted it to play a sound but it seems like you can only make it play sound files on your computer. I could do it, but for the effort, so many people would fail the installation that it's not worth.
Hi AmejiOrape, long time no see. You can play system sounds using C#. Here's how you would play the "Aterisk" sound that comes with windows:
System.Media.SystemSounds.Asterisk.Play();
Add that line of code directly after the code that shows the notification. This will make it so that when someone calls a dungeon, there will also be a sound as well as the text.
Originally Posted by pixelzerg
Hi AmejiOrape, long time no see. You can play system sounds using C#. Here's how you would play the "Aterisk" sound that comes with windows:
System.Media.SystemSounds.Asterisk.Play();
Add that line of code directly after the code that shows the notification. This will make it so that when someone calls a dungeon, there will also be a sound as well as the text.