bot.js 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. var { Client, Attachment } = require('discord.js');
  2. const UserStorage = require('./user-storage')
  3. const session = require('./session')
  4. var bot = new Client()
  5. /*
  6. bot.on('ready', function() {
  7. // console.log('ready', arguments)
  8. console.log('Logged in as %s - %s\n', bot.username, bot.id);
  9. });
  10. */
  11. bot.on('message', async function(message) {
  12. try {
  13. if (message.author.id === bot.user.id) return;
  14. if (message.channel.type === 'dm') {
  15. const state = await UserStorage.get(message.author)
  16. const nextState = await session(message, state)
  17. if (nextState) {
  18. await UserStorage.set(message.author, Object.assign({}, state, nextState))
  19. } else {
  20. console.warn(`Session did not return state for <${message.author}>: ${message.content}.`)
  21. }
  22. }
  23. } catch (e) {
  24. console.error(e)
  25. }
  26. });
  27. const experiment = (message) => {
  28. console.log(message.channel.type, message.toString())
  29. if (message.channel.type === 'dm') {
  30. message.channel.send(`Hello, ${message.author.username}`)
  31. }
  32. }
  33. /*
  34. bot.on("any", function(event) {
  35. console.log(event)
  36. });
  37. */
  38. /*
  39. bot.on('channelCreate', function() { console.log('channelCreate', Array.from(arguments)) })
  40. bot.on('channelDelete', function() { console.log('channelDelete', Array.from(arguments)) })
  41. bot.on('channelPinsUpdate', function() { console.log('channelPinsUpdate', Array.from(arguments)) })
  42. bot.on('channelUpdate', function() { console.log('channelUpdate', Array.from(arguments)) })
  43. bot.on('clientUserGuildSettingsUpdate', function() { console.log('clientUserGuildSettingsUpdate', Array.from(arguments)) })
  44. bot.on('clientUserSettingsUpdate', function() { console.log('clientUserSettingsUpdate', Array.from(arguments)) })
  45. bot.on('debug', function() { console.log('debug', Array.from(arguments)) })
  46. bot.on('disconnect', function() { console.log('disconnect', Array.from(arguments)) })
  47. bot.on('emojiCreate', function() { console.log('emojiCreate', Array.from(arguments)) })
  48. bot.on('emojiDelete', function() { console.log('emojiDelete', Array.from(arguments)) })
  49. bot.on('emojiUpdate', function() { console.log('emojiUpdate', Array.from(arguments)) })
  50. bot.on('error', function() { console.log('error', Array.from(arguments)) })
  51. bot.on('guildBanAdd', function() { console.log('guildBanAdd', Array.from(arguments)) })
  52. bot.on('guildBanRemove', function() { console.log('guildBanRemove', Array.from(arguments)) })
  53. bot.on('guildCreate', function() { console.log('guildCreate', Array.from(arguments)) })
  54. bot.on('guildDelete', function() { console.log('guildDelete', Array.from(arguments)) })
  55. bot.on('guildMemberAdd', function() { console.log('guildMemberAdd', Array.from(arguments)) })
  56. bot.on('guildMemberAvailable', function() { console.log('guildMemberAvailable', Array.from(arguments)) })
  57. bot.on('guildMemberRemove', function() { console.log('guildMemberRemove', Array.from(arguments)) })
  58. bot.on('guildMembersChunk', function() { console.log('guildMembersChunk', Array.from(arguments)) })
  59. bot.on('guildMemberSpeaking', function() { console.log('guildMemberSpeaking', Array.from(arguments)) })
  60. bot.on('guildMemberUpdate', function() { console.log('guildMemberUpdate', Array.from(arguments)) })
  61. bot.on('guildUnavailable', function() { console.log('guildUnavailable', Array.from(arguments)) })
  62. bot.on('guildUpdate', function() { console.log('guildUpdate', Array.from(arguments)) })
  63. bot.on('message', function() { console.log('message', Array.from(arguments)) })
  64. bot.on('messageDelete', function() { console.log('messageDelete', Array.from(arguments)) })
  65. bot.on('messageDeleteBulk', function() { console.log('messageDeleteBulk', Array.from(arguments)) })
  66. bot.on('messageReactionAdd', function() { console.log('messageReactionAdd', Array.from(arguments)) })
  67. bot.on('messageReactionRemove', function() { console.log('messageReactionRemove', Array.from(arguments)) })
  68. bot.on('messageReactionRemoveAll', function() { console.log('messageReactionRemoveAll', Array.from(arguments)) })
  69. bot.on('messageUpdate', function() { console.log('messageUpdate', Array.from(arguments)) })
  70. bot.on('presenceUpdate', function() { console.log('presenceUpdate', Array.from(arguments)) })
  71. bot.on('rateLimit', function() { console.log('rateLimit', Array.from(arguments)) })
  72. bot.on('ready', function() { console.log('ready', Array.from(arguments)) })
  73. bot.on('reconnecting', function() { console.log('reconnecting', Array.from(arguments)) })
  74. bot.on('resume', function() { console.log('resume', Array.from(arguments)) })
  75. bot.on('roleCreate', function() { console.log('roleCreate', Array.from(arguments)) })
  76. bot.on('roleDelete', function() { console.log('roleDelete', Array.from(arguments)) })
  77. bot.on('roleUpdate', function() { console.log('roleUpdate', Array.from(arguments)) })
  78. bot.on('typingStart', function() { console.log('typingStart', Array.from(arguments)) })
  79. bot.on('typingStop', function() { console.log('typingStop', Array.from(arguments)) })
  80. bot.on('userNoteUpdate', function() { console.log('userNoteUpdate', Array.from(arguments)) })
  81. bot.on('userUpdate', function() { console.log('userUpdate', Array.from(arguments)) })
  82. bot.on('voiceStateUpdate', function() { console.log('voiceStateUpdate', Array.from(arguments)) })
  83. bot.on('warn', function() { console.log('warn', Array.from(arguments)) })
  84. */
  85. bot.login('NTEwNTcwNjkzNDM2NjM3MjA5.DsjCpg.f8dNtS13pOlinF6WmMjJD3Xg3Zc')
  86. module.exports = bot