Das stille Plugin nutzt nun Redis!
This commit is contained in:
		@@ -1,21 +1,103 @@
 | 
			
		||||
do
 | 
			
		||||
 | 
			
		||||
function run(msg, matches)
 | 
			
		||||
  local answers = {'Ja, es ist sehr ruhig hier','Wenn es dir zu still ist, kannst du gerne mit mir reden',
 | 
			
		||||
				  '*SCHREI*','Dann mach doch etwas dagegen!','Möpse?','Vermutlich schlafen alle',
 | 
			
		||||
                  'Stört dich die Stille?','Nein, es ist nicht still','Nyu?','Besser als Spam','Stille ist schön',
 | 
			
		||||
                  'Mein Name ist Mikubot','Spiel doch etwas Curvefever.com 😉',
 | 
			
		||||
                  'Stille sagt manchmal mehr als tausend Worte','Spiel doch etwas Agrar.io 😉',
 | 
			
		||||
                  'Stille und Nacht sind untrennbar verwoben. Die Nacht ist die Stille unter den Sternen.',
 | 
			
		||||
				  'Hier könnte Ihre Werbung stehen!','Folge mir auf Twitter! Twitter.com/Mikubot_'}
 | 
			
		||||
  return answers[math.random(#answers)]
 | 
			
		||||
local function save_stille(msg)
 | 
			
		||||
  if msg.text:sub(11):isempty() then
 | 
			
		||||
    return "Benutzung: /addstille [Zitat]"
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  local stille = msg.text:sub(11)
 | 
			
		||||
  local hash = 'telegram:stille'
 | 
			
		||||
  print('Saving stille to redis set '..hash)
 | 
			
		||||
  redis:sadd(hash, stille)
 | 
			
		||||
  return 'Gespeichert: "'..stille..'"'
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function delete_stille(msg)
 | 
			
		||||
  if msg.text:sub(11):isempty() then
 | 
			
		||||
    return "Benutzung: /delstille [Zitat]"
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  local stille = msg.text:sub(11)
 | 
			
		||||
  local hash = 'telegram:stille'
 | 
			
		||||
  print('Deleting stille from redis set '..hash)
 | 
			
		||||
  if redis:sismember(hash, stille) == true then
 | 
			
		||||
    redis:srem(hash, stille)
 | 
			
		||||
    return 'Zitat erfolgreich gelöscht!'
 | 
			
		||||
  else
 | 
			
		||||
    return 'Dieses Zitat existiert nicht.'
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function get_stille(msg)
 | 
			
		||||
  local to_id = tostring(msg.to.id)
 | 
			
		||||
  local hash = 'telegram:stille'
 | 
			
		||||
  
 | 
			
		||||
  if hash then
 | 
			
		||||
    print('Getting stille from redis set '..hash)
 | 
			
		||||
  	local stille_table = redis:smembers(hash)
 | 
			
		||||
	if not stille_table[1] then
 | 
			
		||||
	  return 'Es wurden noch keine Zitate gespeichert.\nSpeichere doch welche mit /addstille [Zitat]'
 | 
			
		||||
	else
 | 
			
		||||
	  return stille_table[math.random(1,#stille_table)]
 | 
			
		||||
	end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function list_stilles(msg)
 | 
			
		||||
  local hash = 'telegram:stille'
 | 
			
		||||
  
 | 
			
		||||
  if hash then
 | 
			
		||||
    print('Getting stille from redis set '..hash)
 | 
			
		||||
    local stille_table = redis:smembers(hash)
 | 
			
		||||
	local text = ""
 | 
			
		||||
    for num,stille in pairs(stille_table) do
 | 
			
		||||
      text = text..num..") "..stille..'\n'
 | 
			
		||||
    end
 | 
			
		||||
	if not text or text == "" then
 | 
			
		||||
	  return 'Es wurden noch keine Zitate gespeichert.\nSpeichere doch welche mit /addstille [Zitat]'
 | 
			
		||||
	else
 | 
			
		||||
	  return text
 | 
			
		||||
	end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function run(msg, matches)
 | 
			
		||||
  if string.match(msg.text, '^[Ss][Tt][IiUu][Ll][Ll][Ee].?$') then
 | 
			
		||||
    return get_stille(msg)
 | 
			
		||||
  elseif matches[1] == "addstille" then
 | 
			
		||||
    if not is_sudo(msg) then
 | 
			
		||||
      return "Du kannst diesen Befehl nicht benutzen!"
 | 
			
		||||
    else
 | 
			
		||||
    return save_stille(msg)
 | 
			
		||||
	end
 | 
			
		||||
  elseif matches[1] == "delstille" then
 | 
			
		||||
    if not is_sudo(msg) then
 | 
			
		||||
      return "Du kannst diesen Befehl nicht benutzen!"
 | 
			
		||||
    else
 | 
			
		||||
      return delete_stille(msg)
 | 
			
		||||
	end
 | 
			
		||||
  elseif matches[1] == "liststille" then
 | 
			
		||||
    if not is_sudo(msg) then
 | 
			
		||||
      return "Du kannst diesen Befehl nicht benutzen!"
 | 
			
		||||
    else
 | 
			
		||||
    return list_stilles(msg)
 | 
			
		||||
	end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return {
 | 
			
		||||
  description = "Es ist so still hier",
 | 
			
		||||
  usage = {"Stille","*Stille*"},
 | 
			
		||||
  patterns = {"^[Ss][Tt][IiUu][Ll][Ll][Ee].?$","^(*)[Ss][Tt][Ii][Ll][Ll][Ee](*)$"},
 | 
			
		||||
  usage = {
 | 
			
		||||
	"stille: Gibt zufälliges Zitat aus."
 | 
			
		||||
  },
 | 
			
		||||
  patterns = {
 | 
			
		||||
    "^/(delstille) (.+)$",
 | 
			
		||||
    "^/(addstille) (.+)$",
 | 
			
		||||
    "^[Ss][Tt][IiUu][Ll][Ll][Ee].?$",
 | 
			
		||||
	"^/(liststille)$"
 | 
			
		||||
  },
 | 
			
		||||
  run = run
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
--by Akamaru [https://ponywave.de]
 | 
			
		||||
		Reference in New Issue
	
	Block a user