[irc-net commit] r63 - wiki

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 12, 2007, 1:55:20 PM8/12/07
to irc-net-d...@googlegroups.com
Author: lord2800
Date: Sun Aug 12 10:54:28 2007
New Revision: 63

Modified:
wiki/PluginTutorial.wiki

Log:
Edited wiki page through web user interface.


Modified: wiki/PluginTutorial.wiki
==============================================================================
--- wiki/PluginTutorial.wiki (original)
+++ wiki/PluginTutorial.wiki Sun Aug 12 10:54:28 2007
@@ -17,6 +17,8 @@
{{{
using Irc;
using Irc.Net;
+using Irc.Events;
+using Irc.Objects;
using System.Windows.Forms;

[assembly: Plugin(typeof(TestPlugin.Test))]
@@ -47,11 +49,15 @@
c.PublicMessage -= MessageResponder;
}
}
- private void MessageResponder(object sender, ChannelMessageEventArgs e)
+ private void MessageResponder(object sender, MessageEventArgs e)
{
Client client = sender as Client;
- if(e.Message == "hi" || e.Message == "hello")
- client.Say(e.Channel.Name, "Hello "+e.Sender.Name+"!");
+ if(e.Message.Text == "hi" || e.Message.Text == "hello")
+ {
+ PublicMessage myMessage = new PublicMessage();
+ myMessage.Text = "Hi "+e.Message.Sender.Name+"!";
+ client.Say(myMessage);
+ }
}
}
}
@@ -78,15 +84,19 @@
}}}
!DebugLogger is the singleton class that implements exception and information logging. Please use this and only this class to log information. It is there for your convenience. It takes two parameters: The message to add and the informative level of the message.
{{{
-private void MessageResponder(object sender, ChannelMessageEventArgs e)
+private void MessageResponder(object sender, MessageEventArgs e)
{
Client client = sender as Client;
- if(e.Message == "hi" || e.Message == "hello")
- client.Say(e.Channel.Name, "Hello "+e.Sender+"!");
+ if(e.Message.Text == "hi" || e.Message.Text == "hello")
+ {
+ PublicMessage myMessage = new PublicMessage();
+ myMessage.Text = "Hi "+e.Message.Sender.Name+"!";
+ client.Say(myMessage);
+ }
}
}}}
This is the core functionality of the plugin. Notice that the Client object is passed to the function as the sender of the event. This is true only if you assign your event handler directly to the !PublicMessage event handler of the Client object. If you attach it to the Channel object, the sender will be a Channel object representing the channel that the message came from.
-The !EventArgs class (in this case !ChannelMessageEventArgs) contains properties which represent parts of the message. The Message property is the actual text of the message, after parsing. Note that Actions and Notices are represented with _different_ events, and are not treated as Messages.
+The !EventArgs class (in this case !MessageEventArgs) contains properties which represent parts of the message. The Message property contains the actual message data, including the time, the target (nickname, server, or channel), and the text of the message.
This particular message handler checks to see if someone said "hi" or "hello" (note the case sensitivity here). If so, it says "Hello" to the sender of the message.

While being an arguably useless plugin, it clearly demonstrates the necessary attributes of the Plugin class.

Reply all
Reply to author
Forward
0 new messages