Move modules to a subfolder

master
Marrub 2017-08-11 21:25:32 -04:00
parent 64bacccb8b
commit 0111991818
7 changed files with 178 additions and 74 deletions

View File

@ -1,72 +0,0 @@
module Vrobot4::Server
class Mod_Base < Vrobot4::Module::Module
def initialize info
super
register :c_help, "help", "Prints documentation for commands."
register :c_die, "die", "Kills all bot instances.", roles: "o"
register :c_modr, "modr", "Reloads a module.", roles: "o"
register :c_modl, "modl", "Loads a module.", roles: "o"
register :c_modu, "modu", "Unloads a module.", roles: "o"
register :c_dbg, "dbg", "Sets the debug level.", roles: "o"
end
def c_help m, argv
check_args argv, "", "S"
if argv.length == 0
cmds = []
m.serv.each_mod {|mod| cmds << mod.all_cmds(m).keys.join(", ")}
cmds.delete ""
m.reply "Commands:", cmds.join(", ")
else
name = argv[0]
m.serv.each_mod do |mod|
if (cmd = mod.get_cmd m, name)
return m.reply name + ":", cmd.help_str
end
end
m.reply "Command not found:", name
end
end
def c_die m, argv
m.serv.voice_quit m if m.serv.flags.include? "A"
m.reply \
["STATUS: DYING",
"ded",
"proceeding to die",
"bye",
"dedededed",
"Thanks, bye!",
"GOTTAGOBYE",
"the orks insisted upon dying"].sample
exit
end
def c_modr m, argv
check_args argv, "S", "S"
m.serv.drop_mod argv[0]
load argv[1], true if argv.length > 1
m.serv.load_mod argv[0]
end
def c_modl m, argv
check_args argv, "S"
m.serv.load_mod argv[0]
end
def c_modu m, argv
check_args argv, "S"
m.serv.drop_mod argv[0]
end
def c_dbg m, argv
check_args argv, "N"
Vrobot4.debug = argv[0].to_i
end
def on_command m, cnam, argv
Vrobot4.log :DEBUGV, "command", cnam.to_s, argv.to_s
super
end
end
end

107
source/modules/mod_audio.rb Normal file
View File

@ -0,0 +1,107 @@
require 'uri'
require 'open-uri'
require 'tempfile'
require 'youtube-dl.rb'
require 'streamio-ffmpeg'
# @!visibility private
class QueueItem
def initialize uri
if uri.scheme == "file"
@fname = uri.path
elsif uri.host and uri.host.include? "youtube.com"
@fname = get_yt_vid_from uri
else
@fname = uri.to_s
end
if (mov = FFMPEG::Movie.new(@fname))
@time = mov.duration
@size = mov.size
else
throw ArgumentError, "File is invalid"
end
end
def get_file
open @fname
end
def cleanup
Vrobot4.log :DEBUGV, "cleaning up audio cruft"
File.delete @tmpf if @tmpf
end
private
def get_yt_vid_from uri
yt_tmp = get_tmp_name "vrobot4_yt_temp_", ".m4a"
mv_tmp = get_tmp_name "vrobot4_mv_temp_", ".mp3"
opt = {
output: yt_tmp,
extract_audio: true,
audio_format: "m4a"
}
YoutubeDL.get uri.to_s, opt
FFMPEG::Movie.new(yt_tmp).transcode(mv_tmp)
File.delete yt_tmp
@tmpf = mv_tmp
end
def get_tmp_name name, ext
fname = Dir::Tmpname.tmpdir + "/"
fname += Dir::Tmpname.make_tmpname name, ext
end
end
class Mod_Audio < Vrobot4::Module::Module
def self.type
"Audio"
end
Vrobot4::Module.add_module_type self, servflags: "A"
def initialize info
super
register :c_summon, "summon", "Brings the bot to your voice channel."
register :c_vanquish, "vanquish", "Kicks the bot from voice.", roles: "o"
register :c_play, "play", "Overwrites the queue.", roles: "o"
register :c_queue, "queue", "Adds an item to the queue."
@queue = []
end
def c_summon m, argv
m.serv.voice_join m
end
def c_vanquish m, argv
m.serv.voice_quit m
end
def c_play m, argv
@queue.clear
push_queue m, argv
start_playback m, qi
end
def c_queue m, argv
push_queue m, argv
start_playback m, qi unless m.serv.is_playing? m
end
private
def push_queue m, argv
m.reply "Queueing '" + uri.to_s + "'..."
uri = URI.parse argv.join(" ")
qi = @queue.push QueueItem.new(uri)
m.reply "'" + uri.to_s + "' loaded (%i sec, %i bytes)" %
[qi.time, qi.size]
end
def start_playback m, qi
m.serv.play m, qi.get_file
end
end
## EOF

View File

@ -1,6 +1,75 @@
require './mod_base.rb'
module Vrobot4::Server
class Mod_Base < Vrobot4::Module::Module
def initialize info
super
register :c_help, "help", "Prints documentation for commands."
register :c_die, "die", "Kills all bot instances.", roles: "o"
register :c_modr, "modr", "Reloads a module.", roles: "o"
register :c_modl, "modl", "Loads a module.", roles: "o"
register :c_modu, "modu", "Unloads a module.", roles: "o"
register :c_dbg, "dbg", "Sets the debug level.", roles: "o"
end
def c_help m, argv
check_args argv, "", "S"
if argv.length == 0
cmds = []
m.serv.each_mod {|mod| cmds << mod.all_cmds(m).keys.join(", ")}
cmds.delete ""
m.reply "Commands:", cmds.join(", ")
else
name = argv[0]
m.serv.each_mod do |mod|
if (cmd = mod.get_cmd m, name)
return m.reply name + ":", cmd.help_str
end
end
m.reply "Command not found:", name
end
end
def c_die m, argv
m.serv.voice_quit m if m.serv.flags.include? "A"
m.reply \
["STATUS: DYING",
"ded",
"proceeding to die",
"bye",
"dedededed",
"Thanks, bye!",
"GOTTAGOBYE",
"the orks insisted upon dying"].sample
exit
end
def c_modr m, argv
check_args argv, "S", "S"
m.serv.drop_mod argv[0]
load argv[1], true if argv.length > 1
m.serv.load_mod argv[0]
end
def c_modl m, argv
check_args argv, "S"
m.serv.load_mod argv[0]
end
def c_modu m, argv
check_args argv, "S"
m.serv.drop_mod argv[0]
end
def c_dbg m, argv
check_args argv, "N"
Vrobot4.debug = argv[0].to_i
end
def on_command m, cnam, argv
Vrobot4.log :DEBUGV, "command", cnam.to_s, argv.to_s
super
end
end
class User
attr_reader :name, :roles
end