├── .ruby-version ├── Procfile ├── Gemfile ├── choose.rb ├── LICENSE ├── README.md ├── .gitignore └── Gemfile.lock /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.0.1 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | bot: bundle exec ruby choose.rb 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | ruby '3.0.1' 6 | 7 | gem 'discordrb', github: 'shardlab/discordrb', branch: 'threads' 8 | gem 'dotenv' 9 | gem 'rubocop', require: false 10 | -------------------------------------------------------------------------------- /choose.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'dotenv/load' 4 | require 'discordrb' 5 | 6 | bot = Discordrb::Commands::CommandBot.new( 7 | token: (ENV['TOKEN']).to_s, 8 | prefix: '!' 9 | ) 10 | 11 | bot.command(:you) do |event, number| 12 | channel = event.user.voice_channel 13 | return event.send_message('Join a voice channel before executing the command!') if channel.nil? 14 | return event.send_message("Huh, seems like you're all muted!") if channel.users.all?(&:self_muted?) 15 | 16 | unmuted_users = channel.users.reject(&:self_muted?) 17 | user_names = unmuted_users.map(&:name) 18 | 19 | chosen_users = 20 | if number == 'all' 21 | user_names.shuffle 22 | else 23 | number = number&.to_i || 1 24 | return event.send_message('The number should be greater than 0!') unless number.positive? 25 | 26 | user_names.sample(number) 27 | end 28 | 29 | event.send_message chosen_users.join(', ') 30 | end 31 | 32 | bot.run 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Miyuki Tomiyama 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # choosing-someone-discord-bot 2 | choosing-someone-discord-botは、Discordのボイスチャンネルに参加しているメンバーをランダムに指名するbotです。 3 | 4 | ## 開発環境 5 | Ruby 3.0.1 6 | 7 | ## 機能概要 8 | - Discordの音声チャンネルに参加し、任意のテキストチャットで`!you`コマンドを実行すると、ボイスチャンネルに参加中のメンバー1人のユーザー名がランダムにテキストチャットに出力されます。 9 | - 音声ミュート状態のメンバーは指名対象外になります。 10 | - `!you 4`のように引数を渡すと、引数分のユーザーが指名できます。 11 | - `!you all`を実行することで、ミュート状態ではないユーザー全員分の名前をランダム順に出力表示できます。 12 | 13 | ## 動作イメージ 14 | ![Gif](https://raw.github.com/wiki/eatplaynap/choosing-someone-discord-bot/wanted.gif) 15 | 16 | ## 利用方法 17 | 利用方法は2つあります。お好みの方法を選択ください。 18 | ### 下記招待URLから追加 19 | https://discord.com/oauth2/authorize?client_id=871997264518856714&permissions=33557504&scope=bot 20 | 21 | ### 自分でDiscordのApplicationの作成 22 | https://discordapp.com/developers/applications/ 23 | - Developer PortalからBotを作成し、発行されたTokenをコードの環境変数に設定 24 | - PRESENCE INTENT、SERVER MEMBERS INTENTを有効にする 25 | - OAuth2 の Scope から Bot をチェックし、下記必要権限にチェックする 26 | - View Channels 27 | - Send Messages 28 | - Use Voice Activity 29 | - 発行されたURLからBotをサーバーに招待する 30 | 31 | ## 起動方法 32 | ### ローカルの場合 33 | `ruby choose.rb`でBotを起動させることができます。 34 | 35 | ### Herokuを利用する場合 36 | デプロイ後、ResourcesタブよりDynoの`bundle exec ruby choose.rb`が有効になっていることを確認してください。 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | /.config 4 | /coverage/ 5 | /InstalledFiles 6 | /pkg/ 7 | /spec/reports/ 8 | /spec/examples.txt 9 | /test/tmp/ 10 | /test/version_tmp/ 11 | /tmp/ 12 | 13 | # Used by dotenv library to load environment variables. 14 | .env 15 | 16 | # Ignore Byebug command history file. 17 | .byebug_history 18 | 19 | ## Specific to RubyMotion: 20 | .dat* 21 | .repl_history 22 | build/ 23 | *.bridgesupport 24 | build-iPhoneOS/ 25 | build-iPhoneSimulator/ 26 | 27 | ## Specific to RubyMotion (use of CocoaPods): 28 | # 29 | # We recommend against adding the Pods directory to your .gitignore. However 30 | # you should judge for yourself, the pros and cons are mentioned at: 31 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 32 | # 33 | # vendor/Pods/ 34 | 35 | ## Documentation cache and generated files: 36 | /.yardoc/ 37 | /_yardoc/ 38 | /doc/ 39 | /rdoc/ 40 | 41 | ## Environment normalization: 42 | /.bundle/ 43 | /vendor/bundle 44 | /lib/bundler/man/ 45 | 46 | # for a library or gem, you might want to ignore these files since the code is 47 | # intended to run in multiple environments; otherwise, check them in: 48 | # Gemfile.lock 49 | # .ruby-version 50 | # .ruby-gemset 51 | 52 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 53 | .rvmrc 54 | 55 | # Used by RuboCop. Remote config files pulled in from inherit_from directive. 56 | # .rubocop-https?--* 57 | .idea 58 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: https://github.com/shardlab/discordrb.git 3 | revision: 32ac7028e223d017f41c8f08be9c4f897a7a5526 4 | branch: threads 5 | specs: 6 | discordrb (3.4.2) 7 | discordrb-webhooks (~> 3.4.2) 8 | ffi (>= 1.9.24) 9 | opus-ruby 10 | rest-client (>= 2.0.0) 11 | websocket-client-simple (>= 0.3.0) 12 | discordrb-webhooks (3.4.2) 13 | rest-client (>= 2.0.0) 14 | 15 | GEM 16 | remote: https://rubygems.org/ 17 | specs: 18 | ast (2.4.2) 19 | domain_name (0.5.20190701) 20 | unf (>= 0.0.5, < 1.0.0) 21 | dotenv (2.7.6) 22 | event_emitter (0.2.6) 23 | ffi (1.15.5) 24 | http-accept (1.7.0) 25 | http-cookie (1.0.4) 26 | domain_name (~> 0.5) 27 | mime-types (3.4.1) 28 | mime-types-data (~> 3.2015) 29 | mime-types-data (3.2022.0105) 30 | netrc (0.11.0) 31 | opus-ruby (1.0.1) 32 | ffi 33 | parallel (1.20.1) 34 | parser (3.0.2.0) 35 | ast (~> 2.4.1) 36 | rainbow (3.0.0) 37 | regexp_parser (2.1.1) 38 | rest-client (2.1.0) 39 | http-accept (>= 1.7.0, < 2.0) 40 | http-cookie (>= 1.0.2, < 2.0) 41 | mime-types (>= 1.16, < 4.0) 42 | netrc (~> 0.8) 43 | rexml (3.2.5) 44 | rubocop (1.18.4) 45 | parallel (~> 1.10) 46 | parser (>= 3.0.0.0) 47 | rainbow (>= 2.2.2, < 4.0) 48 | regexp_parser (>= 1.8, < 3.0) 49 | rexml 50 | rubocop-ast (>= 1.8.0, < 2.0) 51 | ruby-progressbar (~> 1.7) 52 | unicode-display_width (>= 1.4.0, < 3.0) 53 | rubocop-ast (1.9.0) 54 | parser (>= 3.0.1.1) 55 | ruby-progressbar (1.11.0) 56 | unf (0.1.4) 57 | unf_ext 58 | unf_ext (0.0.8) 59 | unicode-display_width (2.0.0) 60 | websocket (1.2.9) 61 | websocket-client-simple (0.5.1) 62 | event_emitter 63 | websocket 64 | 65 | PLATFORMS 66 | x86_64-darwin-20 67 | x86_64-linux 68 | 69 | DEPENDENCIES 70 | discordrb! 71 | dotenv 72 | rubocop 73 | 74 | RUBY VERSION 75 | ruby 3.0.1p64 76 | 77 | BUNDLED WITH 78 | 2.2.28 79 | --------------------------------------------------------------------------------