Просмотр исходного кода

Conversion to command, cleanup

TeraProxy лет назад: 9
Родитель
Сommit
3ff7879f9a
2 измененных файлов с 12 добавлено и 77 удалено
  1. 8 13
      README.md
  2. 4 64
      index.js

+ 8 - 13
README.md

@@ -5,25 +5,20 @@ This has the side effect that the server's AFK check will not kick you out of th
 ## Usage  
 The script is enabled by default and will prevent you from getting logged out when you are standing still for an hour.  
 Simply moving your character will make you able to go back to character selection and reset the 1 hour timer.  
-While ingame, open a whisper chat session with "!AFKer" by typing "/w !afker" in chat and hitting the space bar.
-This serves as the script's command interface. 
-The following commands are supported:  
-  
-* on - Enables the script (default)  
-* off - Disables the script  
   
-Any other input returns a summary of above commands in the game.  
-  
-Alternative commands in all other chats:  
-* !afk - Toggles between "on" and "off" state  
+While in game, open a proxy chat session by typing "/proxy" or "/8" in chat and hitting the space bar.  
+This serves as the script's command interface.  
+The following commands are supported:  
   
-Support for Pinkie Pie's command module:  
-* /proxy afk - Toggles between "on" and "off" state  
+* afk - enable/disable AFKer  
   
 ## Safety
-Whatever you send to "!AFKer" ingame is intercepted client-side. The chat is NOT sent to the server.
+Whatever you send to the proxy chat in game is intercepted client-side. The chat is NOT sent to the server.  
   
 ## Changelog
+### 1.2.1
+* [*] Some code cleanup
+* [*] Full conversion to Pinkie Pie's command module
 ### 1.2.0
 * [+] AFKer will now activate itself after standing still for an hour
 * [*] AFKer is now enabled by default

+ 4 - 64
index.js

@@ -3,14 +3,7 @@ const Command = require('command')
 module.exports = function AFKer(dispatch) {
 	let enabled = true,
 		afk = false,
-		cid = null,
-		player = '',
 		afkCheck = null
-		
-	dispatch.hook('S_LOGIN', 1, event => {
-		({cid} = event)
-		player = event.name
-	})
 	
 	dispatch.hook('C_PLAYER_LOCATION', 1, () => {
 		clearTimeout(afkCheck)
@@ -26,63 +19,10 @@ module.exports = function AFKer(dispatch) {
 	// ### Chat Hook ### //
 	// ################# //
 	
-	dispatch.hook('C_WHISPER', 1, (event) => {
-		if(event.target.toUpperCase() === "!afker".toUpperCase()) {
-			if (/^<FONT>on?<\/FONT>$/i.test(event.message)) {
-				enabled = true
-				message('AFKer <font color="#56B4E9">enabled</font>.')
-			}
-			else if (/^<FONT>off?<\/FONT>$/i.test(event.message)) {
-				enabled = false
-				message('AFKer <font color="#E69F00">disabled</font>.')
-			}
-			else message('Commands:<br>'
-								+ ' "on" (enable AFKer),<br>'
-								+ ' "off" (disable AFKer)'
-						)
-			return false
-		}
-	})
-	
-	function message(msg) {
-		dispatch.toClient('S_WHISPER', 1, {
-			player: cid,
-			unk1: 0,
-			gm: 0,
-			unk2: 0,
-			author: '!AFKer',
-			recipient: player,
-			message: msg
-		})
-	}
-	
-	dispatch.hook('C_CHAT', 1, event => {
-		if(/^<FONT>!afk<\/FONT>$/i.test(event.message)) {
-			if(!enabled) {
-				enabled = true
-				message('AFKer <font color="#56B4E9">enabled</font>.')
-				console.log('AFKer enabled.')
-			}
-			else {
-				enabled = false
-				message('AFKer <font color="#E69F00">disabled</font>.')
-				console.log('AFKer disabled.')
-			}
-			return false
-		}
-	})
-	
 	const command = Command(dispatch)
-	command.add('afk', function() {
-		if(!enabled) {
-			enabled = true
-			message('AFKer <font color="#56B4E9">enabled</font>.')
-			console.log('AFKer enabled.')
-		}
-		else {
-			enabled = false
-			message('AFKer <font color="#E69F00">disabled</font>.')
-			console.log('AFKer disabled.')
-		}
+	command.add('afk', () => {
+		enabled = !enabled
+		command.message('[AFKer] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
+		console.log('[AFKer] ' + (enabled ? 'enabled' : 'disabled'))
 	})
 }