From b8ce686e11000f03610bd133076e492a4a8c9073 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Mon, 15 Aug 2016 23:26:16 +0200 Subject: [PATCH] =?UTF-8?q?=C3=9Cbernehme=20fehlende=20=C3=84nderungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.lua.example | 14 ++++++++++++-- miku/redis.lua | 32 +++++++++++++++----------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/config.lua.example b/config.lua.example index e47fb20..97fa63a 100644 --- a/config.lua.example +++ b/config.lua.example @@ -14,7 +14,7 @@ return { cli_port = 4567, -- The block of text returned by /start. about_text = [[ -Dies ist die BETA-Version von Mikubot v2. +Dies ist die BETA-Version von Brawlbot v2. Sende /hilfe, um zu starten ]], @@ -24,6 +24,16 @@ Sende /hilfe, um zu starten -- false = only whitelisted users can use inline querys -- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted! enable_inline_for_everyone = true, + + -- Redis settings. Only edit if you know what you're doing. + redis = { + host = '127.0.0.1', + port = 6379, + use_socket = false, -- Set to true, if you need to connect over a socket + socket_path = 'unix:///home/path/to/your/redis/sock', + password = nil, -- Set, if you need a password to connect to redis + database = nil -- Set, if you want to select another database. Default is 0 (use no ""!) + }, errors = { -- Generic error messages used in various plugins. generic = 'An unexpected error occurred.', @@ -51,4 +61,4 @@ Sende /hilfe, um zu starten response = 'I don\'t know what to say to that.' } -} \ No newline at end of file +} diff --git a/miku/redis.lua b/miku/redis.lua index 0f77ae5..33087f5 100644 --- a/miku/redis.lua +++ b/miku/redis.lua @@ -1,13 +1,6 @@ local Redis = require 'redis' local FakeRedis = require 'fakeredis' - -local params = { - host = os.getenv('REDIS_HOST') or '127.0.0.1', - port = tonumber(os.getenv('REDIS_PORT') or 6379) -} - -local database = os.getenv('REDIS_DB') -local password = os.getenv('REDIS_PASSWORD') +local config = require('config') -- Overwrite HGETALL Redis.commands.hgetall = Redis.command('hgetall', { @@ -22,7 +15,15 @@ local redis = nil -- Won't launch an error if fails local ok = pcall(function() - redis = Redis.connect(params) + if config.redis.use_socket and config.redis.socket_path then + redis = Redis.connect(config.redis.socket_path) + else + local params = { + host = config.redis.host, + port = config.redis.port + } + redis = Redis.connect(params) + end end) if not ok then @@ -33,9 +34,6 @@ if not ok then fake_func() fake = FakeRedis.new() - print('\27[31mRedis addr: '..params.host..'\27[39m') - print('\27[31mRedis port: '..params.port..'\27[39m') - redis = setmetatable({fakeredis=true}, { __index = function(a, b) if b ~= 'data' and fake[b] then @@ -45,13 +43,13 @@ if not ok then end }) else - if password then - redis:auth(password) + if config.redis.password then + redis:auth(config.redis.password) end - if database then - redis:select(database) + if config.redis.database then + redis:select(config.redis.database) end end -return redis +return redis \ No newline at end of file