Advertisement
Guest User

Untitled

a guest
Sep 15th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Class used for initial bot configuration
  4. # Modify the following variables to your liking
  5. class Configuration
  6. def initialize( status, output )
  7. @nick = "animebot" # Bot nickname
  8. @user = "animebot" # IRC username
  9. @pass = "" # NickServ password
  10. @version = " " # Version
  11.  
  12. @command = '\?' # Character prefix for commands (escape special chars)
  13.  
  14. @server = "irc.insomnia247.nl" # IPv4 address
  15. @server6 = "irc6.insomnia247.nl" # IPv6 address
  16. @port = 6667 # Normal port
  17. @sslport = 8000 # SSL port
  18. @serverpass = "" # Server connect password
  19. @connectopt = "" # Extra stuff to send on connect
  20.  
  21. @channels = [ "#bot", "#test" ]
  22. # Autojoin channel list
  23.  
  24. @opers = ["D1379594.C161D946.100B7DD9.IP"]
  25. # Opers list
  26.  
  27. @data = "data" # Data directory
  28. @plugins = "plugins" # Plugin directory
  29. #@autoload = [ "core", "ddg", "help", "identified", "login", "seen", "shells", "toolbox", "translate", "twitter" ]
  30. @autoload = [ "core", "toolbox", "title" ]
  31. # Plugin autoload list
  32.  
  33. @antiflood = true # Attempt to mitigate people flooding bot with commands
  34. @floodtime = 5 # Seconds withing which the flood limit is triggered
  35. @floodcut = 30 # Limit on the number of seconds delay before starting to drop
  36.  
  37. @throttle = true # Throttle output to avoid flooding from the bot
  38.  
  39. @autorejoin = true # Rejoin on kick
  40. @rejointime = 3 # Time to wait before rejoin (seconds)
  41.  
  42. @pingwait = false # Wait for server's first PING
  43. @conn_time = 20 # Connect timeout
  44. @timeout = 300 # IRC timeout
  45.  
  46. @use_thread = true # Prefer threading
  47. @use_ipv6 = false # Prefer IPv6
  48. @use_ssl = true # Prefer SSL
  49. @verif_ssl = false # Verify SSL certificate
  50. @rootcert = "/etc/ssl/certs/ca-certificates.crt"
  51. # Path to openssl root certs (Needed if verify_ssl is enabled)
  52.  
  53. @threadfb = true # Allow fallback to sequential processing when threads aren't available
  54. @sslfback = false # Allow fallback to insecure connect when OpenSSL library isn't available
  55.  
  56. @status = status # System object, do not modify
  57. @output = output # System object, do not modify
  58. end
  59.  
  60. # Get/set methods
  61. def nick( nick = "" )
  62. if( nick != "" )
  63. @nick = nick
  64. end
  65. return @nick
  66. end
  67.  
  68. def pass( pass = "" )
  69. if( pass != "" )
  70. @pass = pass
  71. end
  72. return @pass
  73. end
  74.  
  75. def user
  76. return @user
  77. end
  78.  
  79. def version
  80. return @version
  81. end
  82.  
  83. def command( command = '' )
  84. if( command != '' )
  85. @command = command
  86. end
  87. return @command
  88. end
  89.  
  90. def server
  91. if( @use_ipv6 )
  92. return @server6
  93. else
  94. return @server
  95. end
  96. end
  97.  
  98. def port
  99. if( @use_ssl && @status.ssl )
  100. return @sslport
  101. elsif( @use_ssl && @status.ssl && @sslfback )
  102. @output.bad( "Warning: SSL is not available, insecure connection!\n" )
  103. return @port
  104. elsif( @use_ssl && @status.ssl && !@sslfback )
  105. @output.info( "\nSSL is not available, and fallback is disabled.\n" )
  106. Process.exit
  107. else
  108. return @port
  109. end
  110. end
  111.  
  112. def ssl( ssl = "" )
  113. if( ssl != "" )
  114. @use_ssl = ssl
  115. end
  116. return @use_ssl
  117. end
  118.  
  119. def verifyssl( ssl = "" )
  120. if( ssl != "" )
  121. @verif_ssl = ssl
  122. end
  123. return @verif_ssl
  124. end
  125.  
  126. def rootcert
  127. return @rootcert
  128. end
  129.  
  130. def ipv6( ipv6 = "" )
  131. if( ipv6 != "" )
  132. @use_ipv6 = ipv6
  133. end
  134. return @use_ipv6
  135. end
  136.  
  137. def serverpass( pass = "" )
  138. if( pass != "" )
  139. @serverpass = pass
  140. end
  141. return @serverpass
  142. end
  143.  
  144. def connectoptions( opt = "" )
  145. if( opt != "" )
  146. @connectopt = opt
  147. end
  148. return @connectopt
  149. end
  150.  
  151. def threads( threads = "" )
  152. if( threads != "" )
  153. @use_thread = threads
  154. end
  155. return @use_thread
  156. end
  157.  
  158. def threadingfallback
  159. return @threadfb
  160. end
  161.  
  162. def connecttimeout
  163. return @conn_time
  164. end
  165.  
  166. def pingtimeout
  167. return @timeout
  168. end
  169.  
  170. def antiflood ( antiflood = "" )
  171. if( antiflood != "" )
  172. @antiflood = antiflood
  173. end
  174. return @antiflood
  175. end
  176.  
  177. def floodtime ( floodtime = "" )
  178. if( floodtime != "" )
  179. @floodtime = floodtime
  180. end
  181. return @floodtime
  182. end
  183.  
  184. def floodcut ( floodcut = "" )
  185. if( floodcut != "" )
  186. @floodcut = floodcut
  187. end
  188. return @floodcut
  189. end
  190.  
  191. def throttleoutput ( throttle = "" )
  192. if( throttle != "" )
  193. @throttle = throttle
  194. end
  195.  
  196. if( RUBY_VERSION =~ /^1\.8/ )
  197. return false
  198. else
  199. return @throttle
  200. end
  201. end
  202.  
  203. def rejoin( rejoin = "" )
  204. if( rejoin != "" )
  205. @autorejoin = rejoin
  206. end
  207. return @autorejoin
  208. end
  209.  
  210. def rejointime( rejointime = "" )
  211. if( rejointime != "" )
  212. @rejointime = rejointime
  213. end
  214. return @rejointime
  215. end
  216.  
  217. def waitforping( wait = "" )
  218. if( wait != "" )
  219. @pingwait = wait
  220. end
  221. return @pingwait
  222. end
  223.  
  224. def opers( opers = "" )
  225. if( opers != "" )
  226. @opers = opers
  227. end
  228. return @opers
  229. end
  230.  
  231. def channels( channels = "" )
  232. if( channels != "" )
  233. @channels = channels
  234. end
  235. return @channels
  236. end
  237.  
  238. def autoload( autoload = "" )
  239. if( autoload != "" )
  240. @autoload = autoload
  241. end
  242. return @autoload
  243. end
  244.  
  245. def datadir( data = "" )
  246. if( data != "" )
  247. @data = data
  248. end
  249. return @data
  250. end
  251.  
  252. def plugindir( plugins = "" )
  253. if( plugins != "" )
  254. @plugins = plugins
  255. end
  256. return @plugins
  257. end
  258.  
  259. # Check for authorized users
  260. def auth( host, console )
  261. admin = 0
  262.  
  263. if( console ) # No auth needed for console
  264. admin = 1
  265. else
  266. @opers.each do |adminhost|
  267. if( adminhost == host )
  268. admin = 1
  269. end
  270. end
  271. end
  272.  
  273. return( admin == 1 )
  274. end
  275.  
  276. # Function to print out current configuration
  277. def show
  278. if( @status.showconfig )
  279. @output.info( "\nConfiguration:\n" )
  280.  
  281. # General bot info
  282. @output.info( "\tBot info:\n" )
  283. @output.std( "\tNickname:\t\t" + @nick + "\n" )
  284. @output.std( "\tUsername:\t\t" + @user + "\n" )
  285. @output.std( "\tNickServ password:\t" + @pass + "\n" )
  286. @output.std( "\tVersion:\t\t" + @version + "\n" )
  287. @output.std( "\tCommand prefix:\t\t" + @command + "\n" )
  288.  
  289. # Server info
  290. @output.info( "\n\tServer info:\n" )
  291. @output.std( "\tServer (IPv4):\t\t" + @server + "\n" )
  292. @output.std( "\tServer (IPv6):\t\t" + @server6 + "\n" )
  293. @output.std( "\tPrefer IPv6:\t\t" + yn(@use_ipv6) + "\n" )
  294. @output.std( "\tPort:\t\t\t" + @port.to_s + "\n" )
  295. @output.std( "\tSSL port:\t\t" + @sslport.to_s + "\n" )
  296. @output.std( "\tSSL Available:\t\t" + yn(@status.ssl) + "\n" )
  297. @output.std( "\tVerify SSL cert:\t" + yn(@verif_ssl) + "\n" )
  298. @output.std( "\tPath to root cert:\t" + @rootcert + "\n" )
  299. @output.std( "\tPrefer SSL:\t\t" + yn(@use_ssl) + "\n" )
  300. @output.std( "\tFallback if no SSL:\t" + yn(@sslfback) + "\n" )
  301. @output.std( "\tConnect timeout:\t" + @conn_time.to_s + " seconds\n" )
  302. @output.std( "\tIRC timeout:\t\t" + @timeout.to_s + " seconds\n" )
  303. @output.std( "\tWait for first PING:\t" + yn(@pingwait) + "\n" )
  304.  
  305. # Channel autojoin
  306. @output.info( "\n\tAuto join channels:\n" )
  307. if( @channels[0] == nil )
  308. @output.std( "\t\t\t\tNone set.\n" )
  309. end
  310. @channels.each do |chan|
  311. @output.std( "\t\t\t\t" + chan + "\n" )
  312. end
  313.  
  314. # Bot admins
  315. @output.info( "\n\tBot admin hosts:\n" )
  316. if( @opers[0] == nil )
  317. @output.std( "\t\t\t\tNone set.\n" )
  318. end
  319. @opers.each do |host|
  320. @output.std( "\t\t\t\t" + host + "\n" )
  321. end
  322.  
  323. # Directory settings
  324. @output.info( "\n\tDirectories:\n" )
  325. @output.std( "\tBot data storage:\t" + @data + "\n" )
  326. @output.std( "\tPlugin directory:\t" + @plugins + "\n" )
  327.  
  328. # Autoload plugins
  329. @output.info( "\n\tAuto load plugins:\n" )
  330. if( @autoload[0] == nil )
  331. @output.std( "\t\t\t\tNone set.\n" )
  332. end
  333. @autoload.each do |plugin|
  334. @output.std( "\t\t\t\t" + plugin + "\n" )
  335. end
  336.  
  337. # Kick settings
  338. @output.info( "\n\tKick settings:\n" )
  339. @output.std( "\tRejoin after kick:\t" + yn(@autorejoin) + "\n" )
  340. @output.std( "\tWait before rejoin:\t" + @rejointime.to_s + " seconds\n" )
  341.  
  342. # Threading settings
  343. @output.info( "\n\tThreading settings:\n" )
  344. @output.std( "\tThreading available:\t" + yn(@status.threads) + "\n" )
  345. @output.std( "\tUse threading:\t\t" + yn(@use_thread) + "\n" )
  346. @output.std( "\tAllow thread fallback:\t" + yn(@threadfb) + "\n" )
  347.  
  348. # Antiflood
  349. @output.info( "\n\tAnti flood settings:\n" )
  350. @output.std( "\tFlood protect:\t\t" + yn(@antiflood) + "\n" )
  351. @output.std( "\tTime between triggers:\t" + @floodtime.to_s + " seconds\n" )
  352.  
  353. # Output settings
  354. @output.info( "\n\tOutput settings:\n" )
  355. @output.std( "\tShow output:\t\tYes\n" )
  356. @output.std( "\tUse colours:\t\t" + yn(@status.colour) + "\n" )
  357. @output.std( "\tShow debug output:\t" + @status.debug.to_s + "\n" )
  358. @output.std( "\tDebug level:\t\t" )
  359. if( @status.debug == 0 )
  360. @output.std( "None\n" )
  361. elsif( @status.debug == 1 )
  362. @output.std( "Normal\n" )
  363. elsif( @status.debug == 2 )
  364. @output.std( "Extra\n" )
  365. else
  366. @output.std( "Extra + IRC threads\n" )
  367. end
  368.  
  369. Process.exit
  370. end
  371. end
  372.  
  373. # Support functions for config printing
  374. def yn( var )
  375. if( var )
  376. return "Yes"
  377. else
  378. return "No"
  379. end
  380. end
  381. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement