Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FuzzWorley/rubot
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: devcenter-square/rubot
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Mar 18, 2017

  1. app to life, initial sign-in

    x6iae committed Mar 18, 2017
    Copy the full SHA
    988225f View commit details

Commits on Mar 20, 2017

  1. assets and UI cleanup

    x6iae committed Mar 20, 2017
    Copy the full SHA
    16f1433 View commit details
  2. Copy the full SHA
    cc7da18 View commit details

Commits on Mar 26, 2017

  1. Copy the full SHA
    0ca1681 View commit details

Commits on Mar 28, 2017

  1. Copy the full SHA
    30e947a View commit details
  2. restoring the thread;

    x6iae committed Mar 28, 2017
    Copy the full SHA
    958b640 View commit details

Commits on Mar 31, 2017

  1. Copy the full SHA
    a426604 View commit details

Commits on Apr 1, 2017

  1. Copy the full SHA
    f522531 View commit details

Commits on Apr 2, 2017

  1. add newrelic for monitoring

    x6iae committed Apr 2, 2017
    Copy the full SHA
    777655e View commit details

Commits on Apr 3, 2017

  1. logging res

    x6iae committed Apr 3, 2017
    Copy the full SHA
    21a428f View commit details
  2. removed track logging

    x6iae committed Apr 3, 2017
    Copy the full SHA
    62cc968 View commit details
  3. Copy the full SHA
    847d927 View commit details

Commits on Apr 14, 2017

  1. Copy the full SHA
    8fca94e View commit details
  2. Add Puma to Gemfile

    x6iae committed Apr 14, 2017
    Copy the full SHA
    0c42526 View commit details
  3. Copy the full SHA
    9ddcdd9 View commit details
  4. Copy the full SHA
    3ab6682 View commit details
  5. migration commands for eb

    x6iae committed Apr 14, 2017
    Copy the full SHA
    a601a87 View commit details

Commits on Apr 15, 2017

  1. add puma configurations

    x6iae committed Apr 15, 2017
    Copy the full SHA
    4ad1f09 View commit details
  2. Copy the full SHA
    75a6910 View commit details
  3. Copy the full SHA
    a542ef4 View commit details

Commits on May 9, 2017

  1. Copy the full SHA
    f08d426 View commit details

Commits on May 12, 2017

  1. pinching client start

    x6iae committed May 12, 2017
    Copy the full SHA
    e67457d View commit details
  2. un-pinching client start

    x6iae committed May 12, 2017
    Copy the full SHA
    17da45e View commit details
  3. prepping puma

    x6iae committed May 12, 2017
    Copy the full SHA
    f185757 View commit details
  4. moves initialization off

    x6iae committed May 12, 2017
    Copy the full SHA
    efe0c32 View commit details
  5. moves initialization off

    x6iae committed May 12, 2017
    Copy the full SHA
    8197500 View commit details

Commits on May 13, 2017

  1. improving workers/thread count

    x6iae committed May 13, 2017
    Copy the full SHA
    53eca29 View commit details

Commits on May 30, 2017

  1. Copy the full SHA
    2d42194 View commit details

Commits on Aug 13, 2017

  1. sort out alert message ui

    x6iae committed Aug 13, 2017
    Copy the full SHA
    f4ea842 View commit details
  2. Copy the full SHA
    a89ffab View commit details
  3. Copy the full SHA
    41f0d60 View commit details
  4. Copy the full SHA
    475bec6 View commit details
  5. code clean

    x6iae committed Aug 13, 2017
    Copy the full SHA
    4de3a72 View commit details
  6. blast that blast

    x6iae committed Aug 13, 2017
    Copy the full SHA
    5f976a7 View commit details
  7. UI cleanup

    x6iae committed Aug 13, 2017
    Copy the full SHA
    0806bf1 View commit details
  8. removes deploy.rb

    x6iae committed Aug 13, 2017
    Copy the full SHA
    3235416 View commit details

Commits on Sep 2, 2017

  1. removes docker

    x6iae committed Sep 2, 2017
    Copy the full SHA
    b1c0cec View commit details
  2. !initialize <=> conditionals

    x6iae committed Sep 2, 2017
    Copy the full SHA
    ec9f4cb View commit details
  3. Copy the full SHA
    099cb57 View commit details
  4. removes segment traces

    x6iae committed Sep 2, 2017
    Copy the full SHA
    068e8f9 View commit details
  5. enables message schedulling

    x6iae committed Sep 2, 2017
    Copy the full SHA
    122ff9a View commit details

Commits on Sep 3, 2017

  1. re-arange back on create form

    x6iae committed Sep 3, 2017
    Copy the full SHA
    8891663 View commit details
  2. asserts interactions

    x6iae committed Sep 3, 2017
    Copy the full SHA
    1d482dc View commit details
  3. Copy the full SHA
    537a4ca View commit details
  4. clean out repeated notice tags

    x6iae committed Sep 3, 2017
    Copy the full SHA
    ab74538 View commit details
  5. fix turbolinks

    x6iae committed Sep 3, 2017
    Copy the full SHA
    e1e777c View commit details
  6. cleaned up users list

    x6iae committed Sep 3, 2017
    Copy the full SHA
    ca4a287 View commit details
  7. paginates user list

    x6iae committed Sep 3, 2017
    Copy the full SHA
    4bd5fc0 View commit details

Commits on Sep 6, 2017

  1. Copy the full SHA
    2522e52 View commit details
  2. rate-limits

    x6iae committed Sep 6, 2017
    Copy the full SHA
    6879fb3 View commit details
Showing with 630 additions and 926 deletions.
  1. +0 −4 .dockerignore
  2. +4 −0 .ebextensions/commands.config
  3. +3 −0 .ebextensions/packages.config
  4. +5 −1 .gitignore
  5. +0 −19 Dockerfile
  6. +8 −12 Gemfile
  7. +17 −8 Gemfile.lock
  8. +0 −1 README.html
  9. +4 −82 README.md
  10. BIN app/assets/images/dc_logo.png
  11. BIN app/assets/images/rubotspeak.png
  12. BIN app/assets/images/udacity_logo.png
  13. +10 −3 app/assets/javascripts/application.js
  14. +0 −7 app/assets/stylesheets/application.css
  15. +0 −3 app/assets/stylesheets/blasts.scss
  16. +29 −0 app/assets/stylesheets/paginate.scss
  17. +0 −1 app/controllers/blasts_controller.rb
  18. +2 −1 app/controllers/callbacks_controller.rb
  19. +1 −5 app/controllers/users_controller.rb
  20. +11 −14 app/models/admin.rb
  21. +6 −22 app/models/blast.rb
  22. +190 −140 app/models/client.rb
  23. +9 −7 app/models/user.rb
  24. +43 −0 app/schedulers/blast_scheduler.rb
  25. +0 −3 app/views/admins/sessions/new.html.erb
  26. +4 −16 app/views/blasts/index.html.erb
  27. +1 −11 app/views/blasts/new.html.erb
  28. +0 −1 app/views/blasts/show.html.erb
  29. +0 −13 app/views/home/index.html.erb
  30. +20 −36 app/views/interactions/index.html.erb
  31. +0 −4 app/views/interactions/new.html.erb
  32. +0 −5 app/views/interactions/show.html.erb
  33. +12 −0 app/views/layouts/_flash_messages.html.erb
  34. +0 −9 app/views/layouts/_user_widget.html.erb
  35. +17 −20 app/views/layouts/application.html.erb
  36. +0 −1 app/views/logs/index.html.erb
  37. +0 −1 app/views/logs/show.html.erb
  38. +0 −12 app/views/messages/edit.html.erb
  39. +34 −46 app/views/messages/index.html.erb
  40. +2 −13 app/views/messages/new.html.erb
  41. +0 −1 app/views/messages/show.html.erb
  42. +1 −12 app/views/metrics/index.html.erb
  43. +38 −51 app/views/users/index.html.erb
  44. +0 −56 app/views/users/index2.html.erb
  45. +0 −15 circle.yml
  46. +5 −16 config/application.rb
  47. +6 −5 config/database.yml
  48. +4 −4 config/initializers/analytics_ruby.rb
  49. +0 −6 config/initializers/assets.rb
  50. +6 −14 config/initializers/devise.rb
  51. +8 −0 config/initializers/slack_client.rb
  52. +50 −0 config/newrelic.yml
  53. +22 −0 config/puma.rb
  54. +1 −55 config/routes.rb
  55. +0 −16 deploy.rb
  56. +0 −19 docker-compose.yml
  57. +0 −32 lib/client_user.rb
  58. +57 −0 lib/google_analytics.rb
  59. +0 −97 lib/segment_analytics.rb
  60. +0 −6 rootfs/etc/cont-init.d/02-run-migrations.sh
4 changes: 0 additions & 4 deletions .dockerignore

This file was deleted.

4 changes: 4 additions & 0 deletions .ebextensions/commands.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
container_commands:
db_migrate:
command: rake db:migrate
leader_only: true
3 changes: 3 additions & 0 deletions .ebextensions/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
yum:
postgresql93-devel: []
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -20,4 +20,8 @@
/config/application.yml
.env*
.DS_Store
public/assets/**
public/assets/**
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
19 changes: 0 additions & 19 deletions Dockerfile

This file was deleted.

20 changes: 8 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@ gem 'jquery-rails'
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# wrapper for the Slack RTM API and its dependencies
gem 'slack-ruby-client'
gem 'eventmachine'
@@ -49,22 +47,15 @@ gem 'net-telnet'
gem 'power_assert'
gem 'psych'
gem 'rake'
gem 'rdoc'
gem 'test-unit'
gem 'tzinfo-data'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'will_paginate', '~> 3.1.0'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Pry to pry... go figure
gem 'pry-rails'
end

group :development do
@@ -75,3 +66,8 @@ group :development do
gem 'spring'
end

group :production do
gem 'puma'
gem 'newrelic_rpm'
end

25 changes: 17 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ GEM
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (8.2.4)
coderay (1.1.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
@@ -94,6 +95,7 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221)
@@ -103,6 +105,7 @@ GEM
multi_xml (0.5.5)
multipart-post (2.0.0)
net-telnet (0.1.1)
newrelic_rpm (3.10.0.279)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
oauth2 (1.0.0)
@@ -125,7 +128,14 @@ GEM
orm_adapter (0.5.0)
pg (0.18.4)
power_assert (0.2.7)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
psych (2.0.17)
puma (3.8.2)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
@@ -154,8 +164,6 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.1.2)
rdoc (4.2.2)
json (~> 1.4)
responders (2.1.2)
railties (>= 4.2.0, < 5.1)
rspec (3.4.0)
@@ -179,9 +187,6 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
slack-ruby-client (0.7.0)
activesupport
faraday
@@ -190,6 +195,7 @@ GEM
hashie
json
websocket-driver
slop (3.6.0)
spring (1.7.1)
sprockets (3.6.0)
concurrent-ruby (~> 1.0)
@@ -221,6 +227,7 @@ GEM
websocket-driver (0.6.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
will_paginate (3.1.5)

PLATFORMS
ruby
@@ -241,25 +248,27 @@ DEPENDENCIES
json
minitest
net-telnet
newrelic_rpm
omniauth
omniauth-google-oauth2
pg
power_assert
pry-rails
psych
puma
rails (= 4.2.5.1)
rake
rdoc
rspec
rufus-scheduler
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
slack-ruby-client
spring
test-unit
turbolinks
tzinfo-data
uglifier (>= 1.3.0)
web-console (~> 2.0)
will_paginate (~> 3.1.0)

BUNDLED WITH
1.11.2
1.14.6
1 change: 0 additions & 1 deletion README.html
Original file line number Diff line number Diff line change
@@ -1082,7 +1082,6 @@ <h2 id="customize-the-bot-for-your-own-team"><a name="user-content-customize-the
<p>In <code>/config/application.rb</code> set the following variables to fit your needs:<br />
<code>Rails.application.config.client_name =</code><br />
<code>Rails.application.config.ndkey =</code><br />
<code>Rails.application.config.standard_responses =</code></p>
<p>Replace <code>rubot_profile_pic.png</code> in <code>/app/assets/images/</code> with your bot&rsquo;s logo. Be sure to leave the file name the same OR change the image tags throughout the project. </p>
</li>
</ol>
86 changes: 4 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RuBot!<img src="app/assets/images/rubot_profile_pic.png" alt="RuBot logo" width= "250"/>
======

An expirement in onboarding for the Udacity Rubyists Slack team! If desired, RuBot can be cloned, customized, and deployed to suit the needs of your Slack team.
~~An expirement in onboarding for the Udacity Rubyists Slack team!~~ [Cloned](https://github.com/FuzzWorley/rubot) and customized for the DC slack team.

[Watch a short demo video](https://www.youtube.com/watch?v=4mlgRz-lgVw).

@@ -17,8 +17,6 @@ An expirement in onboarding for the Udacity Rubyists Slack team! If desired, RuB

Set user input, or trigger words, and a response. The bot will respond whenever somebody sends the trigger word to it.

![Alt text](https://github.com/udacity/RuBot/blob/master/app/assets/images/rubotspeak.png)

3. **Blasts**

Send a direct message from the bot to every user on your team.
@@ -31,90 +29,14 @@ An expirement in onboarding for the Udacity Rubyists Slack team! If desired, RuB

The UI also contains information about every user on your team and some metrics about bot usage.

See [RuBot's UI](https://rubot.udacity.com/)
See [**Original** RuBot's UI](https://rubot.udacity.com/)


## Customize the bot for your own team.

RuBot is a Rails app built to be (somewhat) easily reproduced and customized. To set up your own custom version of RuBot, follow these instructions:

1. **Create your bot user on Slack**

You'll need Slack admin priveledges to do this. Visit this link: [Create bot user](https://my.slack.com/services/new/bot)

Follow the setup instructions. You don't need to set anything except for the name and upload an image.

Copy the API token and keep in a safe place.

2. **Obtain Google Oauth credentials**

Visit: https://console.developers.google.com/ and get a client_id and client_secret from the Google+ API to use for authentication OR you can use my keys if you want to skip this step.

Setup your Authorized redirect URIs using this format:
https://yourbotname.udacity.com/admins/auth/google_oauth2/callback

replacing yourbotname with your bot's name.

3. **Clone the repository**

`git clone https://github.com/udacity/RuBot.git`

4. **Create a branch for your bot**

Your branch name should be your bot name. Ex: `git checkout -b yourbotname`. It will serve as your master branch. Please DO NOT PUSH TO MASTER, unless you've made a change that should propagate to all bots.

5. **Set ENV variables**

Testing: Create a file named `application.yml` in the project root directory containing the following text:

```
SLACK_TOKEN: "<put your testing team token here>"
CLIENT_ID: "<your google oauth client id>"
CLIENT_SECRET: "<your google oauth client secret>"
```

Production: Go to https://circleci.com/gh/udacity/rubot/edit#env-vars and set your ENV vars with the following format:
```
YOURBOTNAME_SLACK_TOKEN
YOURBOTNAME_CLIENT_ID
YOURBOTNAME_CLIENT_SECRET
YOURBOTNAME_SECRET_KEY_BASE
```
To get `YOURBOTNAME_SECRET_KEY_BASE` token, navigate to your project's root directory in terminal, and execute this command: `RAILS_ENV=production rake secret`. You will need to have Rails installed for this command to work. If you don't have Rails installed and don't want to install it, ping @fuzz, and I can get this key for you.

6. **Create branch for Circle CI**

Open `circle.yml` and add the following to the bottom of the file:

```
yourbotname:
branch: "yourbotname"
commands:
- ./deploy.rb
```
replacing yourbotname with your bot's name.

7. **Customize**

In `/config/application.rb` set the following variables to fit your needs:
```
Rails.application.config.client_name =
Rails.application.config.ndkey =
Rails.application.config.standard_responses =
```
Replace `rubot_profile_pic.png` in `/app/assets/images/` with your bot's logo. Be sure to leave the file name the same OR change the image tags throughout the project.
## Deployment instructions
When you push to your bot's branch, it will automatically build and deploy through CircleCI! If you want to push to your branch without deploying include `[ci skip]` in the commit message.
Original codebase with instructions for customizing can also [be found here](https://github.com/FuzzWorley/rubot#customize-the-bot-for-your-own-team)

## Analytics

The program is already setup to be tracking your teams metrics via segment / chartio integration. You will however need to invite your bot user into each channel that you want to run analytics on.
Your teams separating factor is the `ndkey` value in the tracks and indentifies sent to segment. This is automatically configured in the Customize step above.
## Contributors
The program is setup to be tracking the teams metrics via google analytics integration. However, the bot needs to be invited into each channel that you want to run analytics on.

Contributors include Fuzz Worley, Colt Steele, and Angel Perez.
Binary file added app/assets/images/dc_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/assets/images/rubotspeak.png
Binary file not shown.
Binary file removed app/assets/images/udacity_logo.png
Binary file not shown.
13 changes: 10 additions & 3 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,13 @@
//= require turbolinks
//= require_tree .

$('.ui.accordion')
.accordion()
;
var ready;
ready = function() {
$('.ui.accordion').accordion();
$('.inline.icon').popup({inline: true});
$('.icon').popup({inline: true});
$(".ui.mini.rounded.image").popup({inline: true});
};

$(document).ready(ready);
$(document).on('page:load', ready);
7 changes: 0 additions & 7 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -165,10 +165,3 @@ i.circular.send.icon:hover, i.circular.comments.icon:hover, i.circular.users.ico
color: #02b3e4;
}

/*margin-top: -25px;
margin-top: 13px;*/




3 changes: 0 additions & 3 deletions app/assets/stylesheets/blasts.scss

This file was deleted.

29 changes: 29 additions & 0 deletions app/assets/stylesheets/paginate.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.flickr_pagination {
text-align: center;
padding: 0.3em;
cursor: default; }
.flickr_pagination a, .flickr_pagination span, .flickr_pagination em {
padding: 0.2em 0.5em; }
.flickr_pagination .disabled {
color: #aaaaaa; }
.flickr_pagination .current {
font-style: normal;
font-weight: bold;
color: #ff0084; }
.flickr_pagination a {
border: 1px solid #dddddd;
color: #0063dc;
text-decoration: none; }
.flickr_pagination a:hover, .flickr_pagination a:focus {
border-color: #003366;
background: #0063dc;
color: white; }
.flickr_pagination .page_info {
color: #aaaaaa;
padding-top: 0.8em; }
.flickr_pagination .previous_page, .flickr_pagination .next_page {
border-width: 2px; }
.flickr_pagination .previous_page {
margin-right: 1em; }
.flickr_pagination .next_page {
margin-left: 1em; }
1 change: 0 additions & 1 deletion app/controllers/blasts_controller.rb
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ def create

respond_to do |format|
if @blast.save
Blast.schedule_blasts(Rails.application.config.client)
format.html { redirect_to @blast, notice: 'Blast was successfully created.' }
format.json { render :show, status: :created, location: @blast }
else
3 changes: 2 additions & 1 deletion app/controllers/callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ def google_oauth2
if @admin.email != ""
sign_in_and_redirect @admin
else
# this will probable never get thrown now. todo: limit sign-in to DC admins?
puts "Auth ERROR!!!"
redirect_to new_admin_session_path, flash: {error: 'You must log in with your Udacity or Knowlabs email address.' }
redirect_to new_admin_session_path, flash: {error: 'You probably are not an admin of the DC community... :stuck_out_tongue:' }
end
end
end
6 changes: 1 addition & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -4,11 +4,7 @@ class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
@users = User.all.order(:user_name)
end

def index2
@users = User.all
@users = User.page(params[:page]).order(:user_name)
end

# GET /users/1
25 changes: 11 additions & 14 deletions app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -2,22 +2,19 @@ class Admin < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:google_oauth2]
:rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:google_oauth2]

#:registerable removed to disable signup
#:recoverable removed to disable password recovery
#:registerable removed to disable signup
#:recoverable removed to disable password recovery

def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |admin|
if auth.info.email =~ /\A[\w+-.]+@udacity.com|knowlabs.com\z/i
admin.provider = auth.provider
admin.uid = auth.uid
admin.email = auth.info.email
admin.password = Devise.friendly_token[0,20]
else
puts "Auth ERRRRRROOOOOORRR!!!!!"
end
end
where(provider: auth.provider, uid: auth.uid).first_or_create do |admin|
# todo: prolly wanna limit this to the devcenter admins?
admin.provider = auth.provider
admin.uid = auth.uid
admin.email = auth.info.email
admin.password = Devise.friendly_token[0,20]
end
end
end
28 changes: 6 additions & 22 deletions app/models/blast.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
class Blast < ActiveRecord::Base

def self.send_blast(channel_id, blast, client)
client.web_client.chat_postMessage(
channel: channel_id,
text: blast.text,
as_user: true,
unfurl_links: false,
unfurl_media: false
)
end
after_create :schedule_for_broadcast

def schedule_for_broadcast
s = Rufus::Scheduler.new(max_work_threads: 2000)

def self.schedule_blasts(client)
blast = Blast.last
time = Time.now + 5
api_members = client.web_client.users_list.members
User.all.each do |user|
if api_members.any? { |member| member.id == user.slack_id } && user.channel_id
time += 2
s = Rufus::Scheduler.new(:max_work_threads => 1000)
s.at time do
send_blast(user.channel_id, blast, client)
puts "Sent BLAST FOR USER #{user.user_name} AT #{Time.now}"
end
end
s.in '10s' do
BlastScheduler.schedule(self)
end
end
end
330 changes: 190 additions & 140 deletions app/models/client.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,110 @@
class Client < ActiveRecord::Base
require 'pp'
include SegmentAnalytics

include HTTParty
include GoogleAnalytics
include ClientUser

def setup_client
puts "setup rubot!"
@rubot = Slack::RealTime::Client.new(websocket_ping: 40)
# Override the CA_FILE and CA_PATH in the embedded web client if they are set in the environment
if ENV['CA_FILE'] and ENV['CA_PATH']
web_client = Slack::Web::Client.new(ca_file: ENV['CA_FILE'], ca_path: ENV['CA_PATH'], websocket_ping: 40)
@rubot.web_client = web_client
end
@rubot
end
base_uri 'google-analytics.com'

require 'pp'

def initiate

def say_hello_on_start(client)
client.on :hello do
client = Slack::RealTime::Client.new

client.on :hello do
puts "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
get_bot_user(client)
end

client.on :message do |data|
track_message(data)
respond_to_message(data: data, client: client)
end

client.on :team_join do |data|
send_scheduled_messages(client: client, data: data)
add_new_user(data)
end

client.on :user_change do |data|
update_user(data)
end

client.on :close do |_data|
puts 'Connection closing, exiting.'
initiate_another_client
end

client.on :closed do |_data|
puts 'Connection has been disconnected.'
end

# Other setups we need
set_channel_info(client)
set_channel_id(client)
reschedule_messages(client)
update_user_list(client) #todo: maybe put this in a rake file

Rails.application.config.client = client

client.start_async
end

def get_bot_user_id(client)
client.on :hello do
get_users
puts "Bot name: #{client.self.name}"
bot = @users.select { |bot| bot.user_name == client.self.name }.first
#Set global to be used for health check and "respond_to_messages"
Rails.application.config.bot_id = bot.slack_id
puts "Bot ID: #{Rails.application.config.bot_id}"
def channel_id_to_name(data)
channel = nil
if @@channel_list
channel = @@channel_list.select {|channel| channel.id == data.channel}.first
end
channel != nil ? channel.name : "nil"
end

def track_messages(client)
client.on :message do |data|
track_message(data)
private
def add_new_user(data)
get_users
unless @users.any? { |person| person.slack_id == data.user.id }
@user = User.new(
user_name: data.user.name,
real_name: data.user.profile.real_name,
slack_id: data.user.id,
email: data.user.profile.email,
pic: data.user.profile.image_192,
channel_id: client.web_client.im_open(user: data.user.id).channel.id
)
@user.save
# identify(@user)
end
end

def send_message(channel_id, text, client)
def update_user(data)
puts "A user changed! (And I'm still running. Yay!)"
set_user(data)
@user.user_name = data.user.name
@user.real_name = data.user.profile.real_name
@user.slack_id = data.user.id
@user.email = data.user.profile.email
@user.pic = data.user.profile.image_192
@user.save
# identify(@user)
end

def get_bot_user(client)
get_users
puts "Bot name: #{client.self.name}"
bot = @users.select { |bot| bot.user_name == client.self.name }.first
#Set global to be used for health check and "respond_to_messages"
Rails.application.config.bot_id = bot.slack_id
puts "Bot ID: #{Rails.application.config.bot_id}"
end

def send_message(channel, text, client)
client.web_client.chat_postMessage(
channel: channel_id,
channel: channel,
text: text,
as_user: true,
unfurl_links: false,
unfurl_media: false
)
)
end

def create_log(user, message)
@@ -58,104 +118,77 @@ def create_log(user, message)
@log.save
end

def send_scheduled_messages(client)
client.on :team_join do |data|
sleep(2)
set_user(data)
@messages = Message.all.sort
@messages.each do |message|
create_log(@user, message)
s = Rufus::Scheduler.new(:max_work_threads => 200)
s.in message.delay do
ActiveRecord::Base.connection_pool.with_connection do
send_message(@user.channel_id, message.text, client)
track_scheduled_message(@user, message.id, message.text)
message.reach += 1
message.save
Log.where(message_id: message.id).first.delete
end
def send_scheduled_messages(client:, data:)
sleep(2)
set_user(data)
@messages = Message.all.sort
@messages.each do |message|
create_log(@user, message)
s = Rufus::Scheduler.new(:max_work_threads => 200)
s.in message.delay do
ActiveRecord::Base.connection_pool.with_connection do
send_message(@user.channel_id, message.text, client)
track_scheduled_message(@user, message.id, message.text)
message.reach += 1
message.save
Log.where(message_id: message.id).first.delete
end
end
end
end

def reschedule_messages(client)
Log.all.each do |log|
if log.delivery_time > Time.now
s = Rufus::Scheduler.new(:max_work_threads => 200)
s.at log.delivery_time do
ActiveRecord::Base.connection_pool.with_connection do
message = Message.find(log.message_id)
send_message(log.channel_id, message.text, client)
track_rescheduled_message(log, log.message_id, message.text)
message.reach += 1
message.save
log.delete
end
end
end
end
end
def respond_to_message(data:, client:)
return if data.user == Rails.application.config.bot_id
channel = data.channel

def respond_to_messages(client)
client.on :message do |data|
#make sure bot only responds to other users and only in DM channels
if data.user != Rails.application.config.bot_id && data.channel[0] == "D" && data.text
if interaction = Interaction.where(user_input: data.text.downcase).first
send_message(data.channel, interaction.response, client)
track_interactions(data, interaction.id, interaction.user_input, interaction.response)
interaction.hits += 1
interaction.save
else
#if no matching interaction, send from a standard response set in "application.rb"
send_message(data.channel, Rails.application.config.standard_responses.sample, client)
track_interactions(data, 0, "no trigger", "standard_response")
end
if channel[0] == "D" && data.text
if interaction = Interaction.where(user_input: data.text.downcase).first
text = interaction.response
track_interactions(data, interaction.id, interaction.user_input, text)
interaction.hits += 1
interaction.save
else
text = get_response_for_data(data)
track_interactions(data, 0, "no trigger", "standard_response")
end

send_message(channel, text, client)
end
end

def start_rubot(client)
puts "START RUBOT!!!"
client.start!
end
def get_response_for_data(data)
feedback_resp = "To give us a feedback, use `feedback:`... eg: `feedback: You are awesome!!!`"

def kill_client_for_testing(client)
s = Rufus::Scheduler.new
s.in '15s' do
# puts "Client before #{client.web_client.channels_list.channels}"
puts "killing connection"
client.stop!
# sleep(15)
# puts "Client after #{client.web_client.channels_list.channels}"
case data.text
when "help", "Help"
if Interaction.any?
interactions = Interaction.all.map{ |i| "`#{i.user_input}`" }
interactions << feedback_resp
interactions.join("\n")
else
"Nothing configured at the moment, do check back later."
end
when /^feedback:/
post_feedback(data)
"Thank you for the feedback, it has been logged, and will be addressed"
else
<<~RESPONSE
Hi <@#{data.user}>!, sorry, I do not have response for this message...,
For a list of possible interactions, type `help`
#{feedback_resp}
RESPONSE
end
end

def restart_client_if_connection_lost(client)
# kill_client_for_testing(client)
client.on :close do |data|
puts 'Connection has been disconnected. Restarting.'
Rails.application.config.client = setup_client
restart_bot(Rails.application.config.client)
end
end
def post_feedback(data)
client = Rails.application.config.client
channel = User.find_by(user_name: ENV['FEEDBACKS_TO']).channel_id
text = ">#{data.text.gsub('feedback:', '').strip}\nFrom: <@#{data.user}>"

# This method is just for fun.
def argue_with_slackbot(client)
client.on :message do |data|
if data.user == "USLACKBOT"
client.web_client.chat_postMessage(
channel: data.channel,
text: "slackbot... what a dweeb.",
as_user: true,
unfurl_links: false,
unfurl_media: false
)
end
end
send_message(channel, text, client)
end

#Grabs the channel data from slack's api
#Grabs the channel data from slack's api
#to be used by "channel_id_to_name" method
def set_channel_info(client)
@@channel_list = nil
@@ -170,40 +203,57 @@ def set_channel_info(client)
end
end

#Set channel names for "track_message" method in segment_analytics.rb
def channel_id_to_name(data)
channel = nil
if @@channel_list
channel = @@channel_list.select {|channel| channel.id == data.channel}.first
def reschedule_messages(client)
Log.all.each do |log|
if log.delivery_time > Time.now
s = Rufus::Scheduler.new(:max_work_threads => 200)
s.at log.delivery_time do
ActiveRecord::Base.connection_pool.with_connection do
message = Message.find(log.message_id)
send_message(log.channel_id, message.text, client)
track_rescheduled_message(log, log.message_id, message.text)
message.reach += 1
message.save
log.delete
end
end
end
end
channel_name = channel != nil ? channel.name : "nil"
end

def initialize_bot(client)
say_hello_on_start(client)
set_channel_info(client)
track_messages(client)
update_user_list(client)
set_channel_id(client)
get_bot_user_id(client)
add_new_user(client)
reschedule_messages(client)
send_scheduled_messages(client)
update_user(client)
respond_to_messages(client)
restart_client_if_connection_lost(client)
start_rubot(client)
end

def restart_bot(client)
say_hello_on_start(client)
track_messages(client)
add_new_user(client)
send_scheduled_messages(client)
update_user(client)
respond_to_messages(client)
restart_client_if_connection_lost(client)
start_rubot(client)
def initiate_another_client
Client.new.initiate
end

# ######################################################################################################################
# # STUFFS WE WANT TRACKED
# ######################################################################################################################

def word_count(text)
return '0' unless text.is_a? String
text.split.count
end

def emoji_count(text)
return '0' unless text.is_a? String
text.scan(/:[a-z_0-9]*:/m).count
end

def excla_count(text)
return '0' unless text.is_a? String
text.count('!')
end

def elipse_count(text)
return '0' unless text.is_a? String
text.scan(/\.\.\./m).count
end

def question_mark(text)
return '0' unless text.is_a? String
text.count('?')
end

# ######################################################################################################################

end
16 changes: 9 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class User < ActiveRecord::Base
require 'pp'
validates :slack_id, uniqueness: true

# for pagination.
self.per_page = 10

def get_student_data(user)
puts user
key = HTTParty.post(
"https://registrar-window-api.udacity.com/authenticate",
:body =>
@@ -40,12 +42,12 @@ def memberships_nil?(data, user)

def set_subscriptions(type, data, user)
#Case of user with free and paid?
data["memberships"][type].each do |object|
if object["group_key"] == Rails.application.config.ndkey
user.enrolled = "As of #{Time.now.strftime('%D')}: #{type}"
user.save
end
end
# data["memberships"][type].each do |object|
# if object["group_key"] == Rails.application.config.ndkey
# user.enrolled = "As of #{Time.now.strftime('%D')}: #{type}"
# user.save
# end
# end
if user.enrolled == nil
user.enrolled = "As of #{Time.now.strftime('%D')}: NOT ENROLLED"
user.save
43 changes: 43 additions & 0 deletions app/schedulers/blast_scheduler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class BlastScheduler

def self.schedule(blast)
api_members_ids = client.web_client.users_list.members.map(&:id)
users_slack_id = User.select(:slack_id).map(&:slack_id)
current_users_slack_id = api_members_ids & users_slack_id
client_users = User.where(slack_id: current_users_slack_id)

time = Time.now + 5
rs = Rufus::Scheduler.new(max_work_threads: 1000)

client_users.each do |user|
# DO NOT SPAM!!! send message at 2sec intervals. https://api.slack.com/docs/rate-limits
time += 2
rs.at time do
send_blast(user.channel_id, blast.text)
end
end

# TODO: Just for debugging, remove this soon
feedback_channel = User.find_by(user_name: ENV['FEEDBACKS_TO']).channel_id
time += 2
rs.at time do
send_blast(feedback_channel, "DONE!!! Another successful blast to #{client_users.count} available members of DC-square")
end

end

def self.send_blast(channel_id, text)
client.web_client.chat_postMessage(
channel: channel_id,
text: text,
as_user: true,
unfurl_links: false,
unfurl_media: false
)
end

private
def self.client
@client ||= Rails.application.config.client
end
end
3 changes: 0 additions & 3 deletions app/views/admins/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

<div class="main ui text container">
<p id="notice"><%= flash[:error] %></p>
<div>
<div class="ui icon message">
<%= image_tag("rubot_profile_pic.png", :class => "ui floated left image tiny") %>
@@ -12,7 +10,6 @@
<p><%= link_to 'Log Out', destroy_admin_session_path, :method => :delete %> </p>
<% else %>
<div class="header">
<p>Please sign in with your Udacity email.</p>
<button class="ui labeled left floated red icon button">
<i class="google icon"></i>
<%= link_to "Sign in with Google", admin_omniauth_authorize_path(:google_oauth2) %>
20 changes: 4 additions & 16 deletions app/views/blasts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<div class="ui grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<p id="notice"><%= notice %></p>

<div class="column">
<div class="ui segment" id="spacer">
<div class="header">
<h1 class="blue">Blasts</h1>
<i class="help teal inline circular icon link" data-html="<div class='header'>Blasts</div><div class='content'> Blasts are sent to <strong>all</strong> members of the Slack team at the time of creation. <br><br>When you click 'create',<%=" #{Rails.application.config.client_name}" %> will message every user on your team!</div>">
</i>

<button class="ui labeled teal icon small button right floated ">
<%= link_to new_blast_path, class: "ui labeled teal icon small button right floated " do %>
<i class="write icon"></i>
<%= link_to 'New Blast', new_blast_path %>
</button>
<i>New Blast</i>
<% end %>
</div>
<div class="ui divider"></div>

@@ -43,13 +40,4 @@
</table>
</div>
</div>
<div class="two wide column"></div>
</div>

<script type="text/javascript" charset="utf-8" >
$('.inline.icon')
.popup({
inline: true
})
;
</script>
12 changes: 1 addition & 11 deletions app/views/blasts/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= link_to 'Back', messages_path %>

<div class="ui main text container">
<div class="ui segment">
<h1 class="ui teal header">
@@ -10,14 +8,6 @@
</h1>

<%= render 'form' %>
<%= link_to 'Back', blasts_path %>
</div>
</div>


<script type="text/javascript" charset="utf-8" >
$('.inline.icon')
.popup({
inline: true
})
;
</script>
1 change: 0 additions & 1 deletion app/views/blasts/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p id="notice"><%= notice %></p>
<div class="ui grid">
<div class="five wide column"></div>
<div class="six wide column">
13 changes: 0 additions & 13 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<div class="ui main text container">
<div class="ui segment">

<p id="notice"><%= notice %></p>



<%= image_tag("rubot_profile_pic.png", :class => "ui floated left image tiny ") %>

<h1 class="ui header">Welcome to <%= "#{Rails.application.config.client_name}" %>'s control panel!</h1>
@@ -62,11 +57,3 @@ View and search the list of slack users

</div>
</div>

<script type="text/javascript" charset="utf-8" >
$('.icon')
.popup({
inline: true
})
;
</script>
56 changes: 20 additions & 36 deletions app/views/interactions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
<div class="ui grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<p id="notice"><%= notice %></p>




<div class="column">
<div class="ui segment" id="spacer">
<div class="header">
<h1 class="blue">Interactions </h1> <i class="help teal inline circular icon link" data-html="<div class='header'>Interactions</div><div class='content'> Interactions are responses that are triggered by specific user messages.<br><br><strong>Note: </strong> all user input is case insensitive</div>"></i>
<button class="ui labeled teal icon small button right floated ">

<%= link_to new_interaction_path, class: 'ui labeled teal icon small button right floated' do %>
<i class="write icon"></i>
<%= link_to 'Create New Interaction', new_interaction_path %>
</button>
<i>Create New Interaction</i>
<% end %>
</div>
<div class="ui divider"></div>

<table class="ui celled striped table">
<thead>
<tr>
<th>User input</th>
<th>Response</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @interactions.sort.each do |interaction| %>
<table class="ui celled striped table">
<thead>
<tr>
<th>User input</th>
<th>Response</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @interactions.sort.each do |interaction| %>
<tr>
<td><%= interaction.user_input %></td>
<td><%= interaction.response %></td>
@@ -35,20 +30,9 @@
<%= link_to 'Edit', edit_interaction_path(interaction), :class => "ui orange basic label" %>
<%= link_to 'Destroy', interaction, method: :delete, :class => "ui red basic label", data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</tbody>
</table>
</div>
<div class="two wide column"></div>
</div>
</div>



<script type="text/javascript" charset="utf-8" >
$('.inline.icon')
.popup({
inline: true
})
;
</script>
4 changes: 0 additions & 4 deletions app/views/interactions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@




<div class="ui main text container">
<div class="ui segment">
<h1 class="ui teal header">
5 changes: 0 additions & 5 deletions app/views/interactions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p id="notice"><%= notice %></p>
<div class="ui grid">
<div class="five wide column"></div>
<div class="six wide column">
@@ -23,7 +22,3 @@
</div>
<div class="five wide column"></div>
</div>




12 changes: 12 additions & 0 deletions app/views/layouts/_flash_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--render flash messages-->
<% if notice %>
<div class="ui positive message">
<i class="close icon"></i>
<%= notice %>
</div>
<% elsif alert %>
<div class="ui negative message">
<i class="close icon"></i>
<%= alert %>
</div>
<% end %>
9 changes: 0 additions & 9 deletions app/views/layouts/_user_widget.html.erb

This file was deleted.

37 changes: 17 additions & 20 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -20,39 +20,36 @@
<div class="ui fixed inverted menu blue">
<div class="ui container blue">
<a href="/" class="header item">
<%= image_tag("udacity_logo.png", :class => "logo") %>
<%= image_tag("dc_logo.png", :class => "logo") %>
<%= "#{Rails.application.config.client_name}" %>
</a>
<%= link_to 'Messages', messages_path, :class => "item" %>
<%= link_to 'Blasts', blasts_path, :class => "item" %>
<%= link_to 'Interactions', interactions_path, :class => "item" %>
<%= link_to 'User List', users_path, :class => "item" %>
<%= link_to 'Metrics', metrics_path, :class => "item" %>
<%= link_to 'Logs', logs_path, :class => "item" %>
<%= link_to 'Messages', messages_path, :class => "item" %>
<%= link_to 'Blasts', blasts_path, :class => "item" %>
<%= link_to 'Interactions', interactions_path, :class => "item" %>
<%= link_to 'User List', users_path, :class => "item" %>
<%= link_to 'Metrics', metrics_path, :class => "item" %>
<%= link_to 'Logs', logs_path, :class => "item" %>

<div class="ui simple right dropdown item">
<% if current_admin %>
<%= current_admin.email %><i class="dropdown icon"></i>
<% if current_admin %>
<%= current_admin.email %><i class="dropdown icon"></i>
<div class="menu">
<%= link_to "Log Out", destroy_admin_session_path, :method => :delete, :class => "item" %>

</div>
<% else %>
</div>
<% else %>
User <i class="dropdown icon"></i>
<div class="menu">
<%= link_to "Sign In", destroy_admin_session_path, :method => :delete, :class => "item" %>
</div>
<% end %>

</div>
<% end %>
</div>
</div>
</div>

<!-- <div class="ui main text container"> -->
<p class="alert"><%= alert %></p>
<%= render 'layouts/user_widget' %>
<%= yield %>
<!-- </div> -->
<div class="ui main container">
<%= render 'layouts/flash_messages' %>
<%= yield %>
</div>


</body>
1 change: 0 additions & 1 deletion app/views/logs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="ui segment main text container">
<p id="notice"><%= notice %></p>

<h1>Logs</h1>
<h3>You can ignore this page if you're not debugging.</h3>
1 change: 0 additions & 1 deletion app/views/logs/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Channel:</strong>
12 changes: 0 additions & 12 deletions app/views/messages/edit.html.erb
Original file line number Diff line number Diff line change
@@ -18,15 +18,3 @@
<%= link_to 'Back', messages_path %>
</div>
</div>


<script type="text/javascript" charset="utf-8" >
$('.inline.icon')
.popup({
inline: true
})
;
</script>



80 changes: 34 additions & 46 deletions app/views/messages/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,57 +1,45 @@
<div class="ui grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<p id="notice"><%= notice %></p>

<div class="column">
<div class="ui segment" id="spacer">
<div class="header">
<h1 class="blue">Messages</h1><i class="help teal inline circular icon link" data-html="<div class='header'>Messages</div><div class='content'> Messages are content that are sent to students are scheduled times. <br><br><strong>You can do things like: </strong> <li>Send a welcome message</li><li>Introduce the forums 5 days after a student joins</li></div>"></i>
<button class="ui labeled teal icon small button right floated ">
<h1 class="blue">Messages</h1><i class="help teal inline circular icon link" data-html="<div class='header'>Messages</div><div class='content'> Messages are content that are sent out at scheduled times. <br><br><strong>You can do things like: </strong> <li>Send a welcome message</li><li>Introduce platforms 5 days after a student joins</li></div>"></i>

<%= link_to new_message_path, class: "ui labeled teal icon small button right floated " do %>
<i class="write icon"></i>
<%= link_to 'New Message', new_message_path %>
</button>
<i>New Message</i>
<% end %>
</div>
<div class="ui divider"></div>

<table class="ui celled striped table">
<thead>
<tr>
<th>ID</th>
<th class="six wide">Text</th>
<th>Summary</th>
<th>Delay(seconds)</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% sorted_messages = @messages.sort_by(&:message_number) %>

<% sorted_messages.each do |message| %>
<table class="ui celled striped table">
<thead>
<tr>
<td><%= sorted_messages.index(message) + 1 %></td>
<td><%= message.text %></td>
<td><%= message.project %></td>
<td><%= "#{message.delay} (#{message.message_number})" %></td>
<td>
<%= link_to 'Details', message, :class => "ui teal basic label"%>
<%= link_to 'Edit', edit_message_path(message), :class => "ui orange basic label" %>
<%= link_to 'Delete', message, method: :delete, :class => "ui red basic label", data: { confirm: "Are you sure you want to delete this message? Consider editing instead." } %>
</td>
<th>ID</th>
<th class="six wide">Text</th>
<th>Summary</th>
<th>Delay(seconds)</th>
<th colspan="3"></th>
</tr>
<% end %>
</tbody>
</table>
</div>
</thead>

<tbody>
<% sorted_messages = @messages.sort_by(&:message_number) %>

<% sorted_messages.each do |message| %>
<tr>
<td><%= sorted_messages.index(message) + 1 %></td>
<td><%= message.text %></td>
<td><%= message.project %></td>
<td><%= "#{message.delay} (#{message.message_number})" %></td>
<td>
<%= link_to 'Details', message, :class => "ui teal basic label"%>
<%= link_to 'Edit', edit_message_path(message), :class => "ui orange basic label" %>
<%= link_to 'Delete', message, method: :delete, :class => "ui red basic label", data: { confirm: "Are you sure you want to delete this message? Consider editing instead." } %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="two wide column"></div>
</div>
</div>

<script type="text/javascript" charset="utf-8" >
$('.inline.icon')
.popup({
inline: true
})
;
</script>
15 changes: 2 additions & 13 deletions app/views/messages/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= link_to 'Back', messages_path %>

<div class="ui main text container">
<div class="ui segment">
<h1 class="ui teal header">
@@ -10,15 +8,6 @@
</h1>

<%= render 'form' %>
</div>
<%= link_to 'Back', messages_path %>
</div>
</div>


<script type="text/javascript" charset="utf-8" >
$('.inline.icon')
.popup({
inline: true
})
;
</script>

1 change: 0 additions & 1 deletion app/views/messages/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<p id="notice"><%= notice %></p>
<div class="ui grid">
<div class="five wide column"></div>
<div class="six wide column">
13 changes: 1 addition & 12 deletions app/views/metrics/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="ui grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<p id="notice"><%= notice %></p>

<div class="ui segment" id="spacer">
<div class="ui blue header">
@@ -38,7 +37,6 @@
<div class="ui grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<p id="notice"><%= notice %></p>

<div class="ui segment" id="spacer">
<div class="ui blue header">
@@ -67,13 +65,4 @@
</div>
</div>
<div class="two wide column"></div>
</div>

<p id="notice"><%= notice %></p>


<script type="text/javascript" charset="utf-8" async defer>
$(".ui.mini.rounded.image").popup({
inline: true
});
</script>
</div>
89 changes: 38 additions & 51 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,57 +1,44 @@
<div class="ui grid">
<div class="two wide column"></div>
<div class="twelve wide column">
<p id="notice"><%= notice %></p>

<div class="column">
<div class="ui segment" id="spacer">
<div class="ui blue header">
<h1 class="blue">RubyND Slack Users</h1>
</div>
<div class="ui blue header">
<h1 class="blue">RubyND Slack Users</h1>
</div>

<table class="ui celled striped table">
<thead>
<tr>
<th>Profile Pic</th>
<th>User name</th>
<th>Real name</th>
<th>Slack ID</th>
<th>Email</th>
<th>Member since</th>
<!-- <th>Enrollment</th> -->
<th colspan="3"></th>
</tr>
</thead>
<tbody>

<% @users.each do |user| %>
<tr>
<td><img src="<%= user.pic %>" class="ui mini rounded image" alt="" data-html="<img src='<%= user.pic %>' class='ui rounded image'>"></td>
<td><%= user.user_name %></td>
<td><%= user.real_name %></td>
<td><%= user.slack_id %></td>
<td><%= user.email %></td>
<td><%= user.created_at.strftime("%F") %></td>
<!-- <td><%#= user.enrolled %></td> -->
<table class="ui celled striped table">
<thead>
<tr>
<th>Profile Pic</th>
<th>User name</th>
<th>Real name</th>
<th>Slack ID</th>
<th>Email</th>
<th>Member since</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><img src="<%= user.pic %>" class="ui mini rounded image" alt="" data-html="<img src='<%= user.pic %>' class='ui rounded image'>"></td>
<td><%= user.user_name %></td>
<td><%= user.real_name %></td>
<td><%= user.slack_id %></td>
<td><%= user.email %></td>
<td><%= user.created_at.strftime("%F") %></td>

<td>
<%= link_to 'More', user, :class => "ui teal basic label" %>
<%= link_to 'Delete', user, method: :delete, :class => "ui red basic label", data: { confirm: "Please be sure you are deleting the correct user!! There is no way to add them back aside from restarting the program." } %>
<%#= link_to 'Check Status', users_status_path(:id => user.id), method: :post %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<td>
<%= link_to 'More', user, :class => "ui teal basic label" %>
<%= link_to 'Delete', user, method: :delete, :class => "ui red basic label", data: { confirm: "Please be sure you are deleting the correct user!! There is no way to add them back aside from restarting the program." } %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="digg_pagination">
<%= page_entries_info @users %>
<%= will_paginate @users %>
</div>
</div>
<div class="two wide column"></div>
</div>
</div>

<p id="notice"><%= notice %></p>


<script type="text/javascript" charset="utf-8" async defer>
$(".ui.mini.rounded.image").popup({
inline: true
});
</script>
56 changes: 0 additions & 56 deletions app/views/users/index2.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -23,18 +23,3 @@ test:
override:
- make test

deployment:
rubot:
branch: "rubot"
commands:
- ./deploy.rb

swiftbot:
branch: "swiftbot"
commands:
- ./deploy.rb

introbot:
branch: "introbot"
commands:
- ./deploy.rb
21 changes: 5 additions & 16 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -25,25 +25,14 @@ class Application < Rails::Application

config.autoload_paths += %W(#{config.root}/lib)

# Environmental configurations
config.ga_tracking_id = ENV['GA_TRACKING_ID']

config.after_initialize do
puts "ENV = development? #{Rails.env.development?}"

Rails.application.config.client_name = "introbot"
Rails.application.config.ndkey = "nd000"
Rails.application.config.standard_responses =
[
"I'm sorry, I didn't understand that. For a list of commands, type `help`.",
"I'm just a little bot who doesn't know a lot, but type `help` to see what I can respond to!",
"Hmmmm, I haven't learned that one yet. Type `help` to see what I do know!",
"That sounds interesting, but my bot brain has no idea what it means! Type `help` to see what I can respond to.",
"Ahhh, to be fluent in English! Type `help` to see the limited English that I understand."
]
Rails.application.config.client_name = "rubot"

Thread.new do
@client = Client.new
Rails.application.config.client = @client.setup_client
@client.initialize_bot(Rails.application.config.client)
puts "CLIENT DOWN"
Client.new.initiate unless Rails.env.development?
end

end
11 changes: 6 additions & 5 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -33,8 +33,9 @@ test:

production:
<<: *default
username: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASSWORD'] %>
port: <%= ENV['DB_PORT'] %>
database: <%= ENV['DB_NAME'] %>
host: <%= ENV['DB_HOST'] %>
encoding: unicode
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
8 changes: 4 additions & 4 deletions config/initializers/analytics_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Analytics = Segment::Analytics.new({
write_key: ENV['SEGMENT_WRITE_KEY'],
on_error: Proc.new { |status, msg| print msg }
})
# Analytics = Segment::Analytics.new({
# write_key: ENV['SEGMENT_WRITE_KEY'],
# on_error: Proc.new { |status, msg| print msg }
# })
6 changes: 0 additions & 6 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -9,9 +9,3 @@
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )

Slack.configure do |config|
config.token = ENV['SLACK_TOKEN']
config.logger = Logger.new(STDOUT)
config.logger.level = Logger::WARN
end
20 changes: 6 additions & 14 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
@@ -150,7 +150,6 @@
# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
config.email_regexp = /\A[\w+-.]+@udacity.com|knowlabs.com\z/i

# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
@@ -239,19 +238,12 @@
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.

# Conditional solves the problem with Faraday SSL problems locally.
if Rails.env.development?
config.omniauth :google_oauth2,
ENV['CLIENT_ID'],
ENV['CLIENT_SECRET'],
{:client_options => {:ssl => {:verify => false}}}
else
config.omniauth :google_oauth2,
ENV['CLIENT_ID'],
ENV['CLIENT_SECRET'],
#This is a temporary solution that needs to be fixed ASAP.
{:client_options => {:ssl => {:verify => false}}}
end
google_omniauth_options = {
client_options: {:ssl => {:verify => false}},
hd: 'devcenter.co'
}

config.omniauth :google_oauth2, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], google_omniauth_options

# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
8 changes: 8 additions & 0 deletions config/initializers/slack_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Be sure to restart your server when you modify this file.

Slack.configure do |config|
config.token = ENV['SLACK_TOKEN']
config.logger = Logger.new(STDOUT)
config.logger.level = Logger::WARN
fail 'Missing ENV[SLACK_TOKEN]!' unless config.token
end
50 changes: 50 additions & 0 deletions config/newrelic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This file configures the New Relic Agent. New Relic monitors Ruby, Java,
# .NET, PHP, Python and Node applications with deep visibility and low
# overhead. For more information, visit www.newrelic.com.
#
# Generated April 02, 2017
#
# This configuration file is custom generated for app65384074@heroku.com
#
# For full documentation of agent configuration options, please refer to
# https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration

common: &default_settings
# Required license key associated with your New Relic account.
license_key: <%= ENV['NEWRELIC_LICENSE_KEY'] %>


# Your application name. Renaming here affects where data displays in New
# Relic. For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
app_name: Rubolympics

# To disable the agent regardless of other settings, uncomment the following:
# agent_enabled: false

# Logging level for log/newrelic_agent.log
log_level: info


# Environment-specific settings are in this section.
# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment.
# If your application has other named environments, configure them here.
development:
<<: *default_settings
app_name: Rubolympics (Development)

# NOTE: There is substantial overhead when running in developer mode.
# Do not use for production or load testing.
developer_mode: true

test:
<<: *default_settings
# It doesn't make sense to report to New Relic from automated test runs.
monitor_mode: false

staging:
<<: *default_settings
app_name: Rubolympics (Staging)

production:
<<: *default_settings
22 changes: 22 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
workers 3

# Min and Max threads per worker
threads 1, 3 # relying on more workers

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
if rails_env == 'production'
environment rails_env
daemonize true

app_dir = File.expand_path("../..", __FILE__)

bind "unix:///var/run/puma/my_app.sock"
pidfile "/var/run/puma/my_app.sock"

on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end
end
56 changes: 1 addition & 55 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -3,65 +3,11 @@
resources :logs
resources :interactions
devise_for :admins, :controllers => { :omniauth_callbacks => "callbacks" }
root to: "home#index"
resources :messages
resources :users
resources :metrics
get 'users2' => 'users#index2'
post 'users/status'
get 'healthcheck' => 'healthchecks#check'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
# root 'welcome#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
root to: "home#index"
end
16 changes: 0 additions & 16 deletions deploy.rb

This file was deleted.

19 changes: 0 additions & 19 deletions docker-compose.yml

This file was deleted.

32 changes: 0 additions & 32 deletions lib/client_user.rb
Original file line number Diff line number Diff line change
@@ -42,38 +42,6 @@ def delete_user_on_update_list(api_members)
end
end

def add_new_user(client)
client.on :team_join do |data|
get_users
unless @users.any? { |person| person.slack_id == data.user.id }
@user = User.new(
user_name: data.user.name,
real_name: data.user.profile.real_name,
slack_id: data.user.id,
email: data.user.profile.email,
pic: data.user.profile.image_192,
channel_id: client.web_client.im_open(user: data.user.id).channel.id
)
@user.save
identify(@user)
end
end
end

def update_user(client)
client.on :user_change do |data|
puts "A user changed! (And I'm still running. Yay!)"
set_user(data)
@user.user_name = data.user.name
@user.real_name = data.user.profile.real_name
@user.slack_id = data.user.id
@user.email = data.user.profile.email
@user.pic = data.user.profile.image_192
@user.save
identify(@user)
end
end

def set_user(data)
#will work with responses from :team_join and :user_change events
get_users
57 changes: 57 additions & 0 deletions lib/google_analytics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module GoogleAnalytics

def get_analytics_data(slack_data)
channel_name = channel_id_to_name(slack_data)
user = User.where(slack_id: slack_data.user).first

# following params gotten from https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
{
v: 1, # GA protocal version
tid: Rails.configuration.ga_tracking_id, # tracking ID
cid: user.id, # client ID: identifies particular user
ds: "slack", # data source
cs: "slack", # campaign source
cd1: user.user_name, # these are custom dimension <index> : index is as set on GA
cd2: channel_name,
cm1: word_count(slack_data.text), # these are custom metric <index> : index is as set on GA
cm2: emoji_count(slack_data.text),
cm3: excla_count(slack_data.text),
cm4: elipse_count(slack_data.text),
cm5: question_mark(slack_data.text),
t: "event", # hit type
ec: "slack: #{channel_name} | #{slack_data.channel}", # event category
ea: "post by #{user.user_name}", # Specifies the event action
el: slack_data.text, # event label.
ev: 1 # event value
}
end

def track_message(data)
if data.text
ga_data = get_analytics_data(data)
puts ga_data
track(ga_data)
end
end

def track_scheduled_message(user, message_id, message_text)
# We ain't doing nothing here yet
end

def track_rescheduled_message(log, message_id, message_text)
# We ain't doing nothing here yet
end

def track_interactions(data, id, trigger, response)
# We ain't doing nothing here yet
end

def identify(user)
# We ain't doing nothing here yet
end

def track(ga_data)
self.class.post('/collect', { query: ga_data })
end

end
97 changes: 0 additions & 97 deletions lib/segment_analytics.rb

This file was deleted.

6 changes: 0 additions & 6 deletions rootfs/etc/cont-init.d/02-run-migrations.sh

This file was deleted.