Guest User

Untitled

a guest
May 2nd, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. # automatically auths with Q on quakenet servers
  2.  
  3. class QPlugin < Plugin
  4.  
  5. def help(plugin, topic="")
  6. case topic
  7. when ""
  8. return "qauth plugin: handles Q auths. topics set, identify, register"
  9. when "set"
  10. return "qauth set <user> <password>: set the Q user and password and use it to identify in future"
  11. when "identify"
  12. return "qauth identify: identify with Q (if user and auth are set)"
  13. when "register"
  14. return "qauth register <email>: register with Q, an email on how to proceed will be sent to the email address you provide"
  15. end
  16. end
  17.  
  18. def initialize
  19. super
  20. # this plugin only wants to store strings!
  21. class << @registry
  22. def store(val)
  23. val
  24. end
  25. def restore(val)
  26. val
  27. end
  28. end
  29. end
  30.  
  31. def set(m, params)
  32. @registry['quakenet.user'] = params[:nick]
  33. @registry['quakenet.auth'] = params[:password]
  34. m.okay
  35. end
  36.  
  37. def connect
  38. identify(nil, nil)
  39. end
  40.  
  41. def identify(m, params)
  42. @source = m.replyto
  43. @registry['quakenet.auth'] = params[:password] if params[:password]
  44.  
  45. if @registry.has_key?('quakenet.user') && @registry.has_key?('quakenet.auth')
  46. user = @registry['quakenet.user']
  47. pass = @registry['quakenet.auth']
  48.  
  49. debug "authing with Q using #{user} #{pass}"
  50. @bot.say "Q@CServe.quakenet.org", "auth #{user} #{pass}"
  51. else
  52. m.reply "not configured, try 'qauth set :nick :password' or 'qauth register :email'" if m
  53. end
  54. end
  55.  
  56. def notice(m)
  57. if m.source.user == "TheQBot" && m.source.host = "CServe.quakenet.org"
  58. pp m.message
  59. case m.message
  60. when /a user with that name already exists/i
  61. @bot.say @source, "user with my name already exists, identify if it belongs to you"
  62. when /created successfully/
  63. @registry['quakenet.user'] = @bot.nick
  64. @bot.say @source, "an email on how to proceed should have been sent to #{@email} -- 'qauth identify <password>' next"
  65. when /too many accounts exist from this email address/i
  66. @bot.say @source, "too many accounts on that email address"
  67. when /registration service is unavailable/
  68. @bot.say @source, "the registration service is unavailable, try again later"
  69. when /password incorrect/
  70. @bot.say @source, "username or password incorrect" if @source
  71. when /you are now logged in/i
  72. @bot.say @source, "authed successfully" if @source
  73. when /auth is not available/
  74. @bot.say @source, "already authed" if @source
  75. end
  76. end
  77. end
  78.  
  79. def register_nick(m, params)
  80. # check nick for invalid characters
  81. if @bot.nick =~ /[`~\^\[\]{}|_\\]/
  82. m.reply "for me to be able to register, my nick cannot have any of the following characters: `~^[]{}|_\\"
  83. return
  84. end
  85.  
  86. @email = params[:email]
  87. @source = m.replyto
  88.  
  89. @bot.sendmsg "PRIVMSG", "Q@CServe.quakenet.org", "hello #{@email} #{@email}"
  90. end
  91. end
  92.  
  93. plugin = QPlugin.new
  94. plugin.map 'qauth set :nick :password', :action => "set"
  95. plugin.map 'qauth identify [:password]', :action => "identify"
  96. plugin.map 'qauth register :email', :action => "register_nick"
  97.  
  98. plugin.default_auth('*', false)
Add Comment
Please, Sign In to add comment