index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module.exports = function AFKer(dispatch) {
  2. let enabled = false,
  3. cid = null,
  4. player = ''
  5. dispatch.hook('S_LOGIN', 1, event => {
  6. ({cid} = event)
  7. player = event.name
  8. })
  9. dispatch.hook('C_RETURN_TO_LOBBY', 1, () => {
  10. if (enabled) return false // Prevents you from being automatically logged out while AFK
  11. })
  12. // ################# //
  13. // ### Chat Hook ### //
  14. // ################# //
  15. dispatch.hook('C_WHISPER', 1, (event) => {
  16. if(event.target.toUpperCase() === "!afker".toUpperCase()) {
  17. if (/^<FONT>on?<\/FONT>$/i.test(event.message)) {
  18. enabled = true
  19. message('AFKer <font color="#00EE00">enabled</font>.')
  20. }
  21. else if (/^<FONT>off?<\/FONT>$/i.test(event.message)) {
  22. enabled = false
  23. message('AFKer <font color="#DC143C">disabled</font>.')
  24. }
  25. else message('Commands: "on" (enable AFKer),'
  26. + ' "off" (disable AFKer)'
  27. )
  28. return false
  29. }
  30. })
  31. function message(msg) {
  32. dispatch.toClient('S_WHISPER', 1, {
  33. player: cid,
  34. unk1: 0,
  35. gm: 0,
  36. unk2: 0,
  37. author: '!AFKer',
  38. recipient: player,
  39. message: msg
  40. })
  41. }
  42. }