commit 15b1a2e06ad92496ff6cea021ff5fcce5dfc1d0a Author: Astoria Floyd Date: Sat Oct 30 19:50:51 2021 -0500 Initial import diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..959f6a4 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' +gem 'discordrb' +gem 'toml' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d2303f9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,49 @@ +GEM + remote: https://rubygems.org/ + specs: + discordrb (3.4.0) + discordrb-webhooks (~> 3.3.0) + ffi (>= 1.9.24) + opus-ruby + rest-client (>= 2.0.0) + websocket-client-simple (>= 0.3.0) + discordrb-webhooks (3.3.0) + rest-client (>= 2.1.0.rc1) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) + event_emitter (0.2.6) + ffi (1.15.4) + http-accept (1.7.0) + http-cookie (1.0.4) + domain_name (~> 0.5) + mime-types (3.3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2021.0901) + netrc (0.11.0) + opus-ruby (1.0.1) + ffi + parslet (2.0.0) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) + toml (0.3.0) + parslet (>= 1.8.0, < 3.0.0) + unf (0.1.4) + unf_ext + unf_ext (0.0.8) + websocket (1.2.9) + websocket-client-simple (0.3.0) + event_emitter + websocket + +PLATFORMS + x86_64-linux + +DEPENDENCIES + discordrb + toml + +BUNDLED WITH + 2.2.30 diff --git a/modules/modules.txt b/modules/modules.txt new file mode 100644 index 0000000..626038b --- /dev/null +++ b/modules/modules.txt @@ -0,0 +1,3 @@ +pingcommand +pongcommand +playMusic \ No newline at end of file diff --git a/modules/pingcommand/main.rb b/modules/pingcommand/main.rb new file mode 100644 index 0000000..bf85f15 --- /dev/null +++ b/modules/pingcommand/main.rb @@ -0,0 +1,5 @@ +def pingcommand(bot, bang) + bot.message(with_text: "#{bang}Ping") do |event| + event.respond 'Pong!' + end +end \ No newline at end of file diff --git a/modules/playMusic/main.rb b/modules/playMusic/main.rb new file mode 100644 index 0000000..3e4cae7 --- /dev/null +++ b/modules/playMusic/main.rb @@ -0,0 +1,26 @@ +def playMusic(bot, bang) + bot.message(start_with: "#{bang}Play ") do |event| + message = event.content + author = event.author + voice_channel = author.voice_channel.id + server = event.server + bot.voice_connect(voice_channel) + arguments = message.sub("#{bang}Play ", '').split.first + #event.voice.play_file('./example.mp3') + if arguments.include? "youtu" + event.respond "Playing song! This may take some time." + tempFile = Dir::Tmpname.create(['youtubedlruby-', '.mp3']) {} + cmd = "yt-dlp --extract-audio --audio-format mp3 --output " + tempFile + " " + arguments + system(cmd) + event.voice.play_file(tempFile) + File.delete(tempFile) if File.exist?(tempFile) + bot.voice_destroy(server) + event.respond "Done playing!" + else + event.respond "Invalid youtube link!" + end + end + bot.message(with_text: "#{bang}Play") do |event| + event.respond "Please provide youtube link!" + end +end \ No newline at end of file diff --git a/modules/pongcommand/main.rb b/modules/pongcommand/main.rb new file mode 100644 index 0000000..a718633 --- /dev/null +++ b/modules/pongcommand/main.rb @@ -0,0 +1,5 @@ +def pongcommand(bot, bang) + bot.message(with_text: "#{bang}Pong") do |event| + event.respond 'Ping!' + end +end \ No newline at end of file diff --git a/modules/quit/main.rb b/modules/quit/main.rb new file mode 100644 index 0000000..29d8718 --- /dev/null +++ b/modules/quit/main.rb @@ -0,0 +1,7 @@ +def quit(bot, bang) + bot.message(with_text: "#{bang}Quit") do |event| + break unless event.user.id == 185533351866662913 + bot.send_message(event.channel.id, 'Bot is shutting down') + bot.stop + end +end \ No newline at end of file diff --git a/modules/testcommand/main.rb b/modules/testcommand/main.rb new file mode 100644 index 0000000..74d993c --- /dev/null +++ b/modules/testcommand/main.rb @@ -0,0 +1,3 @@ +def testcommand(string) + puts string +end \ No newline at end of file diff --git a/pingbot.rb b/pingbot.rb new file mode 100755 index 0000000..0495dcc --- /dev/null +++ b/pingbot.rb @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby + +require 'discordrb' +require 'tmpdir' +#require 'toml' + +#$config = TOML.load_file("./config.toml") + +bot = Discordrb::Bot.new token: 'ODc0MDMzNjc4Mjc4MzQ0NzY0.YRBFSw.N_rTx8xQL7cn5E9tSj2IlieTNlk' +bang = '!' + +def loadCommands(bot, bang) + File.foreach("modules/modules.txt", chop: true) { |line| + mod = "./modules/" + line + "/main.rb" + require mod.delete("\n") + send("#{line.delete("\n")}", bot, bang) + } +end + +loadCommands(bot, bang) + +#require './pingcommand.rb' + +#main(bot) +#tomlTest() +bot.run \ No newline at end of file diff --git a/pingcommand.rb b/pingcommand.rb new file mode 100644 index 0000000..4123457 --- /dev/null +++ b/pingcommand.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +def main(bot) + + bot.message(with_text: "#{$bang}Pong") do |event| + event.respond 'Ping!' + end + + bot.message(with_text: "#{$bang}Ping") do |event| + event.respond 'Pong!' + end +end + +def tomlTest() + puts "#{$config}" +end \ No newline at end of file