Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'discordrb'
- require 'yaml'
- require './random.rb'
- tempyaml = YAML.load_file 'quotes.yml'
- r = Rand.new(tempyaml.size)
- d20 = Rand.new(19)
- bot = Discordrb::Commands::CommandBot.new token: 'SECRET GO HERE LOL', client_id: 272095539443662849, prefix: '!'
- #puts "This bot's invite URL is #{bot.invite_url}."
- #puts 'Click on it to invite it to your server.'
- bot.command(:quote, min_args: 0, max_args: 1) do |event, args|
- yml = YAML.load_file 'quotes.yml'
- r.size = yml.size
- if args.nil?
- num = r.next
- else
- num = args.to_i
- if num < 0
- num = yml.count + num
- end
- end
- response = yml[num]
- if response.nil?
- event.respond "I was unable to find a quote with ID #{num}, therefore I am generating a random quote instead."
- num = r.next
- response = yml[num]
- end
- event.respond "Quote ID #{num}: #{response}"
- end
- bot.command(:addquote, min_args: 1) do |event, args|
- yml = YAML.load_file 'quotes.yml'
- size = yml.size
- File.open("quotes.yml", "w") do |file|
- yml[size] = query
- file.write(yml.to_yaml)
- end
- r.size = yml.size
- event.respond "Quote had been added as Quote ID #{size}!"
- end
- bot.command(:quoteadd, min_args: 1) do |event, args|
- yml = YAML.load_file 'quotes.yml'
- size = yml.size
- File.open("quotes.yml", "w") do |file|
- yml[size] = query
- file.write(yml.to_yaml)
- end
- r.size = yml.size
- event.respond "Quote had been added as Quote ID #{size}!"
- end
- bot.command(:grepquote, min_args: 1) do |event, args|
- yml = YAML.load_file 'quotes.yml'
- cnt = 0
- yml.each_pair do |key, value|
- if value.downcase =~ /#{args.downcase}/
- cnt += 1
- end
- end
- if cnt == 0
- event.respond "No matches found for #{args}, try again."
- elsif cnt < 10
- yml.each_pair do |key, value|
- if value.downcase =~ /#{args.downcase}/
- event.respond "Match Found. ID: #{key}, Quote: #{value}"
- end
- end
- else
- event.respond "More then 10 matches found, please limit your search further."
- end
- end
- bot.command(:reparsequotedb) do |event|
- yml = YAML.load_file 'quotes.yml'
- yml2 = {}
- File.open("quotes.yml", "w") do |file|
- yml.keys.each_with_index do |var,i|
- yml2[i] = yml[var]
- end
- file.write(yml2.to_yaml)
- end
- r.size = yml.size
- event.respond "Reparsed DB"
- end
- bot.run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement