Kylie Jo Swistak 6 лет назад
Родитель
Сommit
347e0412eb
7 измененных файлов с 285 добавлено и 0 удалено
  1. 9 0
      .env.template
  2. 1 0
      .gitignore
  3. 16 0
      Gemfile
  4. 85 0
      Gemfile.lock
  5. 86 0
      README.md
  6. 75 0
      bot.rb
  7. 13 0
      config/database.yml

+ 9 - 0
.env.template

@@ -0,0 +1,9 @@
+POSTGRES_USER=rotom
+POSTGRES_PASSWORD=PleaseChangeMe:D
+POSTGRES_DB=pmd
+
+DISCORD_CLIENT_ID=
+DISCORD_SECRET=
+DISCORD_BOT_TOKEN=
+
+DB_HOST_PORT=6543

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.env

+ 16 - 0
Gemfile

@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+source 'https://rubygems.org'
+git_source(:github) { |repo| "https://github.com/#{repo}.git" }
+
+ruby '2.6.3'
+
+gem 'activerecord'
+gem 'discordrb', '~> 3.3.0'
+gem 'pg'
+gem 'terminal-table'
+
+group :development do
+  gem 'dotenv'
+  gem 'pry'
+end

+ 85 - 0
Gemfile.lock

@@ -0,0 +1,85 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    activemodel (6.0.0)
+      activesupport (= 6.0.0)
+    activerecord (6.0.0)
+      activemodel (= 6.0.0)
+      activesupport (= 6.0.0)
+    activesupport (6.0.0)
+      concurrent-ruby (~> 1.0, >= 1.0.2)
+      i18n (>= 0.7, < 2)
+      minitest (~> 5.1)
+      tzinfo (~> 1.1)
+      zeitwerk (~> 2.1, >= 2.1.8)
+    coderay (1.1.2)
+    concurrent-ruby (1.1.5)
+    discordrb (3.3.0)
+      discordrb-webhooks (~> 3.3.0)
+      ffi (>= 1.9.24)
+      opus-ruby
+      rbnacl (~> 3.4.0)
+      rest-client (>= 2.1.0.rc1)
+      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)
+    dotenv (2.7.5)
+    event_emitter (0.2.6)
+    ffi (1.11.1)
+    http-accept (1.7.0)
+    http-cookie (1.0.3)
+      domain_name (~> 0.5)
+    i18n (1.6.0)
+      concurrent-ruby (~> 1.0)
+    method_source (0.9.2)
+    mime-types (3.2.2)
+      mime-types-data (~> 3.2015)
+    mime-types-data (3.2019.0331)
+    minitest (5.11.3)
+    netrc (0.11.0)
+    opus-ruby (1.0.1)
+      ffi
+    pg (1.1.4)
+    pry (0.12.2)
+      coderay (~> 1.1.0)
+      method_source (~> 0.9.0)
+    rbnacl (3.4.0)
+      ffi
+    rest-client (2.1.0.rc1)
+      http-accept (>= 1.7.0, < 2.0)
+      http-cookie (>= 1.0.2, < 2.0)
+      mime-types (>= 1.16, < 4.0)
+      netrc (~> 0.8)
+    terminal-table (1.8.0)
+      unicode-display_width (~> 1.1, >= 1.1.1)
+    thread_safe (0.3.6)
+    tzinfo (1.2.5)
+      thread_safe (~> 0.1)
+    unf (0.1.4)
+      unf_ext
+    unf_ext (0.0.7.6)
+    unicode-display_width (1.6.0)
+    websocket (1.2.8)
+    websocket-client-simple (0.3.0)
+      event_emitter
+      websocket
+    zeitwerk (2.1.9)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  activerecord
+  discordrb (~> 3.3.0)
+  dotenv
+  pg
+  pry
+  terminal-table
+
+RUBY VERSION
+   ruby 2.6.3p62
+
+BUNDLED WITH
+   1.17.2

+ 86 - 0
README.md

@@ -0,0 +1,86 @@
+# Rotom Bot
+_The best ghosty-electric boy that runs your devices! He's also your
+friendly Pokemon Myster Dungeon Bot <3_
+
+## Setup
+This application runs using Ruby and Postgres. In order to run the bot locally
+you can create a bot in the discord developer portal and use it to test
+
+### Windows Users
+  * __Enable Developer Mode__
+
+    Open your settings, and navigate to Update and Security
+
+    On the left, click `For Developers`, and check Developer Mode
+
+  * __Subsystem for Linux__
+
+    Next open the Control Panel, and select `Programs`
+    and select `Turn Windows features on or off` on the side bar
+
+    Search for `Windows Subsystem for Linux`, check it and wait for the
+    install, then restart
+
+  * __Installing bash__
+
+    Now you can open a Command Prompt and type in:
+    ```
+    C:\Users\YourUserName> bash
+    ```
+    If it returns saying you have no installed distributions, open up the
+    Microsoft Store and install Ubuntu (its free), and try again
+
+    If it is asking for verification, reply with `y` and wait for the install
+
+    Once prompted you can provide a username and password of your choice, you
+    should then get a prompt:
+    ```bash
+    username@ComputerName: $
+    ```
+
+### Prereqs
+  * __Installing [RVM](https://rvm.io/rvm/install) and Ruby__
+
+    If you are on Windows, we need to install GPG, and get a public key
+    , install RVM, access the command and then use it to install Ruby
+
+    ```bash
+    $ sudo apt-get install gpg
+    $ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
+    ```
+
+    We can Install RVM and Ruby with the following:
+
+    ```bash
+    $ \curl -sSL https://get.rvm.io | bash -s stable
+    $ rvm install ruby 2.6.3
+    ```
+
+    On Windows we need to access the command before we can use it, so use this command between the two above
+
+    ```bash
+    $ source ~/.rvm/scripts/rvm
+    ```
+
+  * __Install Bundler and Bundle Install__
+
+    ```bash
+    $ gem install bundler
+    $ bundle install
+    ```
+
+  * __Setup Postgresql__
+
+    For Installation and setup instructions visit [postgresql.org](https://www.postgresql.org/download/)
+
+    Create a user and database
+
+    Use the `.env.template` to make an `.env` with the appropriate information
+
+    If you are making a development bot, use the information from the discord developer portal
+
+  * __Run the bot__
+
+  ```bash
+  $ ruby bot.rb
+  ```

+ 75 - 0
bot.rb

@@ -0,0 +1,75 @@
+require 'bundler'
+require 'erb'
+require 'yaml'
+require 'json'
+require 'terminal-table'
+
+BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
+Bundler.require(:default, BOT_ENV)
+
+require 'active_record'
+
+# Constants: such as roles and channel ids
+# ---
+
+Dotenv.load if BOT_ENV != 'production'
+
+db_yml = File.open('config/database.yml') do |erb|
+  ERB.new(erb.read).result
+end
+
+db_config = YAML.safe_load(db_yml)[BOT_ENV]
+ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
+ActiveRecord::Base.establish_connection(
+  adapter: 'postgresql',
+  host: db_config.fetch('host') { 'localhost' },
+  database: db_config['database'],
+  user: db_config['user'],
+  password: db_config['password']
+)
+
+Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
+
+
+token = ENV['DISCORD_BOT_TOKEN']
+bot = Discordrb::Bot.new(token: token)
+
+# Methods: define basic methods here
+# ---
+
+# Commands: structure basic bot commands here
+# ---
+
+# This will trigger on every message sent in discord
+bot.message do |event|
+end
+
+# This will trigger on every reaction is added in discord
+bot.reaction_add do |event|
+end
+
+# This will trigger on every reaction is removed in discord
+bot.reaction_remove do |event|
+end
+
+# This will trigger when a member is updated
+bot.member_update do |event|
+end
+
+# This will trigger when anyone joins the server
+bot.member_join do |event|
+end
+
+# This will trigger when anyone leaves the server
+bot.member_leave do |event|
+end
+
+# This will trigger when anyone is banned from the server
+bot.user_ban do |event|
+end
+
+# This will trigger when anyone is un-banned from the server
+bot.user_unban do |event|
+end
+
+bot.run

+ 13 - 0
config/database.yml

@@ -0,0 +1,13 @@
+development:
+  database: <%= ENV['POSTGRES_DB'] %>
+  user: <%= ENV['POSTGRES_USER'] %>
+  password: <%= ENV['POSTGRES_PASSWORD'] %>
+  host: <%= ENV['POSTGRES_HOST'] %>
+  port: <%= ENV['POSTGRES_PORT'] %>
+
+production:
+  database: <%= ENV['POSTGRES_DB'] %>
+  user: <%= ENV['POSTGRES_USER'] %>
+  password: <%= ENV['POSTGRES_PASSWORD'] %>
+  host: <%= ENV['POSTGRES_HOST'] %>
+  port: <%= ENV['POSTGRES_PORT'] %>