Advertisement
Guest User

Untitled

a guest
Dec 16th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. require! "./util"
  2.  
  3. message-limit = 200
  4. limit = (str, repl = " ...") ->
  5. if str.length > message-limit
  6. then "#{str.substr 0, message-limit - repl.length}#repl"
  7. else str
  8.  
  9. splice = (str, index, count, insert) ->
  10. "#{str.slice 0, index}#insert#{str.slice index + count}"
  11.  
  12. # Insert zero-width space character into nick to
  13. # hopefully prevent them from being pinged in IRC.
  14. ping-protect = (nick) ->
  15. splice nick, 1, 0, "\u200B"
  16.  
  17.  
  18. module.exports = (irc, discord) !->
  19. discord.on \ready, !->
  20. for x in discord.channels
  21. if x.name == "pcl\-minecraft"
  22. x.name = "PCL\-Minecraft"
  23. irc.on \message, (message) !->
  24. if !message.channel? or message.notice or message.own then return
  25. text = limit message.text, message-limit
  26. text = util.irc-to-discord text, discord
  27. util.discord-send-channel discord, message.channel,
  28. if message.action then "\\* **#{message.user}** *#{text - /\s*$/}*"
  29. else "<**#{message.user}**> #text"
  30.  
  31. discord.on \message, (message) !->
  32. # You receive message events from your own sent messages, so ignore those.
  33. if message.author.id == discord.user.id then return
  34. # Only relay messages to channels that the bot is actually in.
  35. if "##{message.channel.name}" !of irc.channels then return
  36.  
  37. channel = "##{message.channel.name}"
  38. from = ping-protect message.author.username
  39. text = limit util.discord-to-irc discord, message
  40.  
  41. # Format message differently if it seems to be a message generated by /me:
  42. # Needs to start and end with a *, no *'s in the message itself, so
  43. # "*this* is *bullshit*" or "*this *is* bullshit* don't count.
  44. if is-action = /^\*[^\*]+\*$/g.test text
  45. text .= substr 1, text.length - 2
  46.  
  47. irc.send channel, if is-action
  48. then "* \x02#from\x0F #text"
  49. else "<\x02#from\x0F> #text"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement