unexist.dev

Changeset 49:f49946ee919b

Switched from sqlite to postgres
author unexist
date Thu, 02 Aug 2018 13:19:27 +0200
parents 7a77bbf6cdd5
children 69e66dea6a86
files slack/slack.rb
diffstat 1 files changed, 26 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/slack/slack.rb	Thu Aug 02 13:10:50 2018 +0200
+++ b/slack/slack.rb	Thu Aug 02 13:19:27 2018 +0200
@@ -4,7 +4,7 @@
 # @file Slack
 
 # @copyright (c) 2018, Christoph Kappel <unexist@subforge.org>
-# @version $Id$
+# @version $Id: cinch.rb,v 20 2015/08/28 10:56:49 unexist $
 #
 # Channel bot for slack
 #
@@ -26,7 +26,9 @@
 # Database # {{{
 DBFILE =  Dir.pwd + "/database.db"
 
-DataMapper.setup(:default, "sqlite3:///" + DBFILE)
+#DataMapper.setup(:default, "sqlite3:///" + DBFILE)
+DataMapper.setup(:default, "postgres://" + ENV["USER"] + ":" +
+  ENV["PASSWORD"] + "@localhost/" + ENV["DATABASE"])
 
 # Models
 class Phrase # {{{
@@ -94,6 +96,20 @@
 DataMapper.auto_migrate!  unless File.exist?(DBFILE)
 DataMapper.finalize # }}}
 
+# Handler
+
+def handleMessage(event) # {{{
+  p event
+
+  REGEXP.each do |r|
+    match = event["text"].match(r[:match])
+
+    unless match.nil?
+      return method(r[:method]).call(event["user"], *match.captures)
+    end
+  end
+end # }}}
+
 # Score handler
 
 def change_score(nick, op, key) # {{{
@@ -164,17 +180,13 @@
   "Oops something went wrong.."
 end # }}}
 
-def handleMessage(event) # {{{
-  p event
-
-  REGEXP.each do |r|
-    match = event["text"].match(r[:match])
+# Protolol handler
 
-    unless match.nil?
-      return method(r[:method]).call(event["user"], *match.captures)
-    end
-  end
-end # }}}
+def protolol(nick) #{{{
+  @protos = IO.readlines("../protolol.txt") if @protos.nil?
+
+  @protos[rand(@protos.size)]
+end #}}}
 
 # Phrase helper
 
@@ -278,7 +290,7 @@
   result
 end #  }}}
 
-# Phrase handler handler
+# Phrase handler
 
 def store_alias(nick, from_key, to_key) # {{{
   store_phrase(from_key, "=", "${%s}" % to_key)
@@ -463,6 +475,7 @@
 # Message Regexp
 
 REGEXP = [
+  { match: /^!proto$/, method: :protolol },
   { match: /(\+\+|--)([^ ].+)/, method: :change_score },
   { match: /score (.+)/, method: :get_score },
   { match: /(best|worst)$/, method: :top_score },