@@ -6,93 +6,95 @@ import Foundation
6
6
loads, it must inherit NSObject to allow proper initialization. */
7
7
/* THOPluginProtocol is the protocol available for plugin specific callbacks.
8
8
It is appended to our new class object to inform Swift that we conform to it. */
9
+
9
10
class TPI_SwiftPluginExample : NSObject , THOPluginProtocol
10
11
{
11
- func subscribedServerInputCommands( ) -> [ AnyObject ] !
12
- {
13
- /* Accept all incoming server data corresponding to the
14
- commands PRIVMSG and NOTICE. The plugin will perform
15
- different actions for each value. */
16
-
17
- return [ " privmsg " , " notice " ]
12
+ var subscribedServerInputCommands : [ AnyObject ] ! {
13
+ get {
14
+ return [ " privmsg " , " notice " ]
15
+ }
18
16
}
19
-
20
- func didReceiveServerInputOnClient ( client : IRCClient ! , senderInformation senderDict : [ NSObject : AnyObject ] ! , messageInformation messageDict : [ NSObject : AnyObject ] ! )
17
+
18
+ func didReceiveServerInput ( inputObject : THOPluginDidReceiveServerInputConcreteObject ! , onClient client : IRCClient ! )
21
19
{
22
20
/* Swift provides a very powerful switch statement so
23
21
it is easier to use that for identifying commands than
24
22
using an if statement if more than the two are added. */
25
- let commandValue = ( messageDict [ THOPluginProtocolDidReceiveServerInputMessageCommandAttribute] as String )
26
23
27
- switch ( commandValue) {
24
+ NSLog ( " %@ %@ " , inputObject. messageCommand, inputObject. messageParamaters)
25
+
26
+ switch ( inputObject. messageCommand) {
28
27
case " PRIVMSG " :
29
- self . handleIncomingPrivateMessageCommand ( client , senderDict : senderDict , messageDict : messageDict )
28
+ self . handleIncomingPrivateMessageCommand ( inputObject , onClient : client )
30
29
case " NOTICE " :
31
- self . handleIncomingNoticeCommand ( client , senderDict : senderDict , messageDict : messageDict )
30
+ self . handleIncomingNoticeCommand ( inputObject , onClient : client )
32
31
default :
33
- return ;
32
+ return
34
33
}
35
34
}
36
-
37
- func handleIncomingPrivateMessageCommand( client : IRCClient ! , senderDict : [ NSObject : AnyObject ] ! , messageDict : [ NSObject : AnyObject ] ! )
35
+
36
+ func handleIncomingPrivateMessageCommand( inputObject : THOPluginDidReceiveServerInputConcreteObject ! , onClient client : IRCClient ! )
38
37
{
39
38
/* Get message sequence of incoming message. */
40
- let messageReceived = ( messageDict [ THOPluginProtocolDidReceiveServerInputMessageSequenceAttribute ] as String )
41
-
42
- let messageParamaters = ( messageDict [ THOPluginProtocolDidReceiveServerInputMessageParamatersAttribute ] as Array < String > )
43
-
39
+ let messageReceived = ( inputObject . messageSequence as String )
40
+
41
+ let messageParamaters = ( inputObject . messageParamaters as! Array < String > )
42
+
44
43
/* Get channel that message was sent from. */
45
44
/* The first paramater of the PRIVMSG command is always
46
45
the channel the message was targetted to. */
47
46
let senderChannel = client. findChannel ( messageParamaters [ 0 ] )
48
-
47
+
49
48
/* Do not accept private messages. */
50
49
if senderChannel. isPrivateMessage {
51
- return ;
50
+ return
52
51
}
53
-
52
+
54
53
/* Get sender of message. */
55
- let messageSender = ( senderDict [ THOPluginProtocolDidReceiveServerInputSenderNicknameAttribute ] as String )
56
-
54
+ let messageSender = ( inputObject . senderNickname as String )
55
+
57
56
/* Ignore this user, he's kind of a jerk. :-( */
58
57
if messageSender. hasPrefix ( " Alex " ) {
59
- return ;
58
+ return
60
59
}
61
-
60
+
62
61
/* Compare it against a specific value. */
63
62
if ( messageReceived == " do you know what time it is? " ||
64
63
messageReceived == " does anybody know what time it is? " )
65
64
{
66
65
/* Format message. */
67
- let formattedString = ( messageSender + " the time where I am is: " + self . formattedDateTimeString ( ) ) ;
68
-
66
+ let formattedString = ( messageSender + " , the time where I am is: " + self . formattedDateTimeString ( ) )
67
+
69
68
/* Invoke the client on the main thread when sending. */
70
69
self . performBlockOnMainThread ( {
71
70
client. sendPrivmsg ( formattedString, toChannel: senderChannel)
72
- } ) ;
71
+ } )
73
72
}
74
73
}
75
-
76
- func handleIncomingNoticeCommand( client : IRCClient ! , senderDict : [ NSObject : AnyObject ] ! , messageDict : [ NSObject : AnyObject ] ! )
74
+
75
+ func handleIncomingNoticeCommand( inputObject : THOPluginDidReceiveServerInputConcreteObject ! , onClient client : IRCClient ! )
77
76
{
78
77
// Not implemented.
79
78
}
80
-
79
+
81
80
/* Support a new command in text field. */
82
- func subscribedUserInputCommands( ) -> [ AnyObject ] !
83
- {
84
- return [ " datetime " ]
81
+ var subscribedUserInputCommands : [ AnyObject ] ! {
82
+ get {
83
+ return [ " datetime " ]
84
+ }
85
85
}
86
86
87
87
func userInputCommandInvokedOnClient( client: IRCClient ! , commandString: String ! , messageString: String ! )
88
88
{
89
- let formattedString = ( " The current time is: " + self . formattedDateTimeString ( ) ) ;
89
+ let formattedString = ( " The current time is: " + self . formattedDateTimeString ( ) )
90
+
91
+ let mainWindow = self . masterController ( ) . mainWindow;
90
92
91
93
self . performBlockOnMainThread ( {
92
- client. sendPrivmsg ( formattedString, toChannel: self . masterController ( ) . mainWindow. selectedChannel)
93
- } ) ;
94
+ client. sendPrivmsg ( formattedString, toChannel: mainWindow. selectedChannel)
95
+ } )
94
96
}
95
-
97
+
96
98
/* Helper functions. */
97
99
func formattedDateTimeString( ) -> ( String )
98
100
{
0 commit comments