Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. ####
  3. ## bnc.im administration bot
  4. ##
  5. ## Copyright (c) 2013 Andrew Northall
  6. ##
  7. ## MIT License
  8. ## See LICENSE file for details.
  9. ####
  10.  
  11. $:.unshift File.dirname(__FILE__)
  12.  
  13. require 'cinch'
  14. require 'cinch/plugins/identify'
  15. require 'yaml'
  16. require 'lib/requests'
  17. require 'lib/relay'
  18. require 'lib/logger'
  19. require 'lib/mail'
  20.  
  21. $config = YAML.load_file("config/config.yaml")
  22. $bots = Hash.new
  23. $zncs = Hash.new
  24. $threads = Array.new
  25.  
  26. # Set up a bot for each server
  27. $config["servers"].each do |name, server|
  28. bot = Cinch::Bot.new do
  29. configure do |c|
  30. c.nick = $config["bot"]["nick"]
  31. c.user = $config["bot"]["user"]
  32. c.realname = $config["bot"]["realname"]
  33. c.server = server["server"]
  34. c.ssl.use = server["ssl"]
  35. c.port = server["port"]
  36. c.channels = $config["bot"]["channels"].map {|c| c = "#" + c}
  37. if $config["admin"]["network"] == name
  38. c.channels << "##{$config["admin"]["channel"]}"
  39. end
  40. unless server["sasl"] == false
  41. c.sasl.username = $config["bot"]["saslname"]
  42. c.sasl.password = $config["bot"]["saslpass"]
  43. c.plugins.plugins = [RequestPlugin, RelayPlugin]
  44. else
  45. c.plugins.plugins = [RelayPlugin, RequestPlugin, Cinch::Plugins::Identify]
  46. c.plugins.options[Cinch::Plugins::Identify] = {
  47. :username => $config["bot"]["saslname"],
  48. :password => $config["bot"]["saslpass"],
  49. :type => :nickserv,
  50. }
  51. end
  52. end
  53. end
  54. bot.loggers.clear
  55. bot.loggers << BNCLogger.new(name, File.open("log/irc-#{name}.log", "a"))
  56. bot.loggers << BNCLogger.new(name, STDOUT)
  57. bot.loggers.level = :info
  58. if $config["admin"]["network"] == name
  59. $adminbot = bot
  60. end
  61. $bots[name] = bot
  62. end
  63.  
  64. # Set up the ZNC bots
  65. $config["zncservers"].each do |name, server|
  66. bot = Cinch::Bot.new do
  67. configure do |c|
  68. c.nick = "bncbot"
  69. c.server = server["addr"]
  70. c.ssl.use = server["ssl"]
  71. c.password = server["username"] + ":" + server["password"]
  72. c.port = server["port"]
  73. end
  74. end
  75. bot.loggers.clear
  76. bot.loggers << BNCLogger.new(name, File.open("log/znc-#{name}.log", "a"))
  77. bot.loggers << BNCLogger.new(name, STDOUT)
  78. bot.loggers.level = :info
  79. $zncs[name] = bot
  80. end
  81.  
  82. # Initialize the RequestDB
  83. RequestDB.load($config["requestdb"])
  84.  
  85. # Start the bots
  86.  
  87. $zncs.each do |key, bot|
  88. $threads << Thread.new { bot.start }
  89. end
  90.  
  91. $bots.each do |key, bot|
  92. $threads << Thread.new { bot.start }
  93. end
  94.  
  95. $threads.each { |t| t.join } # wait for other threads
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement