From e0d3aeb7f93a235879c4a4b2fd8b738b33414dba Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Mon, 15 Aug 2016 18:32:49 +0200 Subject: [PATCH] =?UTF-8?q?Redis-Einstellungen=20werden=20nicht=20mehr=20h?= =?UTF-8?q?ardcodiert=20-=20Einstellungen=20k=C3=B6nnen=20=C3=BCber=20die?= =?UTF-8?q?=20config.lua=20vorgenommen=20werden=20-=20Passw=C3=B6rter=20+?= =?UTF-8?q?=20andere=20Datenbanken=20werden=20unterst=C3=BCtzt=20-=20Bot?= =?UTF-8?q?=20sollte=20damit=20ohne=20weitere=20Anpassung=20OoTB=20f=C3=BC?= =?UTF-8?q?r=20alle=20laufen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.lua.example | 10 ++++++++++ otouto/redis.lua | 26 +++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/config.lua.example b/config.lua.example index 513e6a7..97fa63a 100644 --- a/config.lua.example +++ b/config.lua.example @@ -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.', diff --git a/otouto/redis.lua b/otouto/redis.lua index 419830f..33087f5 100644 --- a/otouto/redis.lua +++ b/otouto/redis.lua @@ -1,10 +1,6 @@ local Redis = require 'redis' local FakeRedis = require 'fakeredis' - - -local params = { - 'unix:///home/anditest/.redis/sock' -} +local config = require('config') -- Overwrite HGETALL Redis.commands.hgetall = Redis.command('hgetall', { @@ -19,7 +15,15 @@ local redis = nil -- Won't launch an error if fails local ok = pcall(function() - redis = Redis.connect('unix:///home/anditest/.redis/sock') -- FUCKING FUCK REDIS LUA FUCK Y U NO WORK WITH 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 @@ -30,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 @@ -41,6 +42,13 @@ if not ok then return fake[b] or fake_func end }) +else + if config.redis.password then + redis:auth(config.redis.password) + end + if config.redis.database then + redis:select(config.redis.database) + end end