@@ -9,49 +9,46 @@ It is appended to our new class object to inform Swift that we conform to it. */
9
9
10
10
class TPI_SwiftPluginExample : NSObject , THOPluginProtocol
11
11
{
12
- var subscribedServerInputCommands : [ AnyObject ] ! {
12
+ var subscribedServerInputCommands : [ String ] {
13
13
get {
14
14
return [ " privmsg " , " notice " ]
15
15
}
16
16
}
17
17
18
- func didReceiveServerInput( inputObject: THOPluginDidReceiveServerInputConcreteObject ! , onClient client: IRCClient ! )
18
+ func didReceiveServerInput( _ inputObject: THOPluginDidReceiveServerInputConcreteObject , on client: IRCClient )
19
19
{
20
20
/* Swift provides a very powerful switch statement so
21
21
it is easier to use that for identifying commands than
22
22
using an if statement if more than the two are added. */
23
-
24
- NSLog ( " %@ %@ " , inputObject. messageCommand, inputObject. messageParamaters)
25
-
26
23
switch ( inputObject. messageCommand) {
27
24
case " PRIVMSG " :
28
- self . handleIncomingPrivateMessageCommand ( inputObject, onClient : client)
25
+ handleIncomingPrivateMessageCommand ( inputObject, on : client)
29
26
case " NOTICE " :
30
- self . handleIncomingNoticeCommand ( inputObject, onClient : client)
27
+ handleIncomingNoticeCommand ( inputObject, on : client)
31
28
default :
32
29
return
33
30
}
34
31
}
35
32
36
- func handleIncomingPrivateMessageCommand( inputObject: THOPluginDidReceiveServerInputConcreteObject ! , onClient client: IRCClient ! )
33
+ func handleIncomingPrivateMessageCommand( _ inputObject: THOPluginDidReceiveServerInputConcreteObject , on client: IRCClient )
37
34
{
38
35
/* Get message sequence of incoming message. */
39
- let messageReceived = ( inputObject. messageSequence as String )
36
+ let messageReceived = inputObject. messageSequence
40
37
41
- let messageParamaters = ( inputObject. messageParamaters as! Array < String > )
38
+ let messageParamaters = inputObject. messageParamaters
42
39
43
40
/* Get channel that message was sent from. */
44
41
/* The first paramater of the PRIVMSG command is always
45
42
the channel the message was targetted to. */
46
43
let senderChannel = client. findChannel ( messageParamaters [ 0 ] )
47
44
48
45
/* Do not accept private messages. */
49
- if senderChannel. isPrivateMessage {
46
+ if ( ( senderChannel? . isPrivateMessage) != nil ) {
50
47
return
51
48
}
52
49
53
50
/* Get sender of message. */
54
- let messageSender = ( inputObject. senderNickname as String )
51
+ let messageSender = inputObject. senderNickname
55
52
56
53
/* Ignore this user, he's kind of a jerk. :-( */
57
54
if messageSender. hasPrefix ( " Alex " ) {
@@ -63,47 +60,47 @@ class TPI_SwiftPluginExample: NSObject, THOPluginProtocol
63
60
messageReceived == " does anybody know what time it is? " )
64
61
{
65
62
/* Format message. */
66
- let formattedString = ( messageSender + " , the time where I am is: " + self . formattedDateTimeString ( ) )
63
+ let formattedString = ( messageSender + " , the time where I am is: " + formattedDateTimeString( ) )
67
64
68
65
/* Invoke the client on the main thread when sending. */
69
- self . performBlockOnMainThread ( {
70
- client. sendPrivmsg ( formattedString, toChannel : senderChannel)
66
+ performBlock ( onMainThread : {
67
+ client. sendPrivmsg ( formattedString, to : senderChannel)
71
68
} )
72
69
}
73
70
}
74
71
75
- func handleIncomingNoticeCommand( inputObject: THOPluginDidReceiveServerInputConcreteObject ! , onClient client: IRCClient ! )
72
+ func handleIncomingNoticeCommand( _ inputObject: THOPluginDidReceiveServerInputConcreteObject , on client: IRCClient )
76
73
{
77
- // Not implemented.
74
+ // Not implemented
78
75
}
79
76
80
77
/* Support a new command in text field. */
81
- var subscribedUserInputCommands : [ AnyObject ] ! {
78
+ var subscribedUserInputCommands : [ String ] {
82
79
get {
83
80
return [ " datetime " ]
84
81
}
85
82
}
86
83
87
- func userInputCommandInvokedOnClient ( client: IRCClient ! , commandString: String ! , messageString: String ! )
84
+ func userInputCommandInvoked ( on client: IRCClient , command commandString: String , messageString: String )
88
85
{
89
- let formattedString = ( " The current time is: " + self . formattedDateTimeString ( ) )
86
+ let formattedString = ( " The current time is: " + formattedDateTimeString( ) )
90
87
91
- let mainWindow = self . masterController ( ) . mainWindow;
88
+ let mainWindow = masterController ( ) . mainWindow
92
89
93
- self . performBlockOnMainThread ( {
94
- client. sendPrivmsg ( formattedString, toChannel : mainWindow. selectedChannel)
90
+ performBlock ( onMainThread : {
91
+ client. sendPrivmsg ( formattedString, to : mainWindow? . selectedChannel)
95
92
} )
96
93
}
97
94
98
95
/* Helper functions. */
99
96
func formattedDateTimeString( ) -> ( String )
100
97
{
101
- let dateFormatter = NSDateFormatter ( )
98
+ let dateFormatter = DateFormatter ( )
102
99
103
- dateFormatter. dateStyle = NSDateFormatterStyle . FullStyle
104
- dateFormatter. timeStyle = NSDateFormatterStyle . FullStyle
100
+ dateFormatter. dateStyle = DateFormatter . Style . fullStyle
101
+ dateFormatter. timeStyle = DateFormatter . Style . fullStyle
105
102
106
- let formattedDate = dateFormatter. stringFromDate ( NSDate ( ) )
103
+ let formattedDate = dateFormatter. string ( from : Date ( ) )
107
104
108
105
return formattedDate
109
106
}
0 commit comments