@@ -1,9 +1,8 @@
POSTGRES_USER=rotom
POSTGRES_PASSWORD=PleaseChangeMe:D
POSTGRES_DB=pmd
+POSTGRES_PORT=5432
DISCORD_CLIENT_ID=
DISCORD_SECRET=
DISCORD_BOT_TOKEN=
-
-DB_HOST_PORT=6543
@@ -39,9 +39,8 @@ class User < ActiveRecord::Base
end
def update_xp(msg_length, member=nil)
- xp =
+ old_xp =
case msg_length
- when 0..39 then 0
when 40..149 then 1
when 150..299 then 2
when 300..599 then 3
@@ -49,9 +48,22 @@ class User < ActiveRecord::Base
else 5
+ multiplier =
+ case msg_length
+ when 50..299 then 1
+ when 300..649 then 1.5
+ when 650..999 then 1
+ else 0.5
+ end
+
+ xp = (msg_length/50 * multiplier).to_i
self.update(
boosted_xp: boosted_xp + xp,
- unboosted_xp: unboosted_xp + xp
+ unboosted_xp: unboosted_xp + xp,
+ additional_xp: additional_xp + (xp - old_xp),
+ post_length: post_length + msg_length,
+ post_count: post_count + 1
)
self.reload
@@ -34,7 +34,8 @@ ActiveRecord::Base.establish_connection(
host: db_config.fetch('host') { 'localhost' },
database: db_config['database'],
user: db_config['user'],
- password: db_config['password']
+ password: db_config['password'],
+ pool: 5
Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
@@ -95,19 +96,24 @@ bot.message do |event|
# Apply experience to non-bot users
elsif !author.bot_account? && !author.webhook?
# Replace any urls with 150 'x' chars
- message = URL.match(content) ? content.gsub(URL, "x" * 150) : content
+ message = URL.match(content) ? content.gsub(URL, "x" * 100) : content
# Add 40 to the message length if there's a file
msg_length = event.message.attachments.map(&:filename).count > 0 ?
- 40 + message.length : message.length
+ 50 + message.length : message.length
- if msg_length >= 40
- # Wait until now to find user, so DB isn't touched for every message
- user = User.find(author.id)
+ # Record post lengths and count
+ user = User.find(author.id)
+ if msg_length >= 40
# Update User and reply with image, if there is one
reply = user.update_xp(msg_length, author)
bot.send_file(event.channel.id, File.open(reply, 'r')) if reply
+ else
+ user.update(
+ short_post_length: user.short_post_length + msg_length,
+ short_post_count: user.short_post_count + 1
+ )
@@ -0,0 +1,9 @@
+#!/bin/bash
+cd $HOME/rotom_bot
+git pull
+docker build . -t rotom_bot:latest
+docker stop rotom_bot
+docker run --env-file .env --name rotom_bot --rm -d rotom_bot:latest
+docker image prune -f
@@ -0,0 +1,15 @@
+[Unit]
+Description=Docker Compose Encapsulated Rotom Discord Bot
+Requires=docker.service
+After=docker.service
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+WorkingDirectory=/srv/docker
+ExecStart=/usr/local/bin/docker-compose up -d
+ExecStop=/usr/local/bin/docker-compose down
+TimeoutStartSec=0
+[Install]
+WantedBy=multi-user.target
@@ -2,6 +2,7 @@ version: "3.7"
services:
bot:
+ restart: unless-stopped
build: .
depends_on:
- db
@@ -9,20 +10,21 @@ services:
- POSTGRES_DB
- POSTGRES_HOST=db
- POSTGRES_PASSWORD
- - POSTGRES_PORT=6543
+ - POSTGRES_PORT
- POSTGRES_USER
- DISCORD_CLIENT_ID
- DISCORD_SECRET
- DISCORD_BOT_TOKEN
db:
image: postgres:11.2-alpine
environment:
ports:
- - ${DB_HOST_PORT}:6543
+ - ${POSTGRES_PORT}:5432
volumes:
- postgres-persisted-volume:/var/lib/postgresql/data
@@ -90,7 +90,7 @@ module Emoji
LETTERS = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
- NUMBERS = [ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN]
+ NUMBERS = [ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, A, B, C, D, E, F]
CHAR_APP = [SPEECH_BUBBLE, PICTURE, BOOKS, NOTE, QUESTION, PEOPLE, WIZARD]
IMG_APP = [DOG, KEY, FLAG, PAGE, BOOKS, VULGAR]