- Portierung folgender Plugins:
+ QR + Random - Remind eingedeutscht, funktioniert gut so, warum also das Rad neu erfinden?
This commit is contained in:
parent
4cbe28ea93
commit
16f4dd169d
86
otouto/plugins/qr.lua
Normal file
86
otouto/plugins/qr.lua
Normal file
@ -0,0 +1,86 @@
|
||||
local qr = {}
|
||||
|
||||
local http = require('socket.http')
|
||||
local URL = require('socket.url')
|
||||
local utilities = require('otouto.utilities')
|
||||
|
||||
function qr:init(config)
|
||||
qr.triggers = {
|
||||
'^/qr "(%w+)" "(%w+)" (.+)$',
|
||||
"^/qr (.+)$"
|
||||
}
|
||||
qr.doc = [[*
|
||||
]]..config.cmd_pat..[[qr* _<Text>_: Sendet QR-Code mit diesem Text
|
||||
*]]..config.cmd_pat..[[qr* _"[Hintergrundfarbe]"_ _"[Datenfarbe]"_ _[Text]_
|
||||
Farbe mit Text: red|green|blue|purple|black|white|gray
|
||||
Farbe als HEX: ("a56729" ist braun)
|
||||
oder Farbe als Dezimalwert: ("255-192-203" ist pink)]]
|
||||
end
|
||||
|
||||
qr.command = 'qr <Text>'
|
||||
|
||||
function qr:get_hex(str)
|
||||
local colors = {
|
||||
red = "f00",
|
||||
blue = "00f",
|
||||
green = "0f0",
|
||||
yellow = "ff0",
|
||||
purple = "f0f",
|
||||
white = "fff",
|
||||
black = "000",
|
||||
gray = "ccc"
|
||||
}
|
||||
|
||||
for color, value in pairs(colors) do
|
||||
if color == str then
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
function qr:qr(text, color, bgcolor)
|
||||
|
||||
local url = "http://api.qrserver.com/v1/create-qr-code/?"
|
||||
.."size=600x600" --fixed size otherways it's low detailed
|
||||
.."&data="..URL.escape(utilities.trim(text))
|
||||
|
||||
if color then
|
||||
url = url.."&color="..qr:get_hex(color)
|
||||
end
|
||||
if bgcolor then
|
||||
url = url.."&bgcolor="..qr:get_hex(bgcolor)
|
||||
end
|
||||
|
||||
local response, code, headers = http.request(url)
|
||||
|
||||
if code ~= 200 then
|
||||
return nil
|
||||
end
|
||||
|
||||
if #response > 0 then
|
||||
return url
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function qr:action(msg, config, matches)
|
||||
local text = matches[1]
|
||||
local color
|
||||
local back
|
||||
|
||||
if #matches > 1 then
|
||||
text = matches[3]
|
||||
color = matches[2]
|
||||
back = matches[1]
|
||||
end
|
||||
|
||||
local image_url = qr:qr(text, color, back)
|
||||
if not image_url then utilities.send_reply(self, msg, config.errors.connection) return end
|
||||
local file = download_to_file(image_url, 'qr.png')
|
||||
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
|
||||
end
|
||||
|
||||
return qr
|
53
otouto/plugins/random.lua
Normal file
53
otouto/plugins/random.lua
Normal file
@ -0,0 +1,53 @@
|
||||
local fun = {}
|
||||
|
||||
local utilities = require('otouto.utilities')
|
||||
|
||||
function fun:init(config)
|
||||
fun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('random', true).table
|
||||
fun.doc = [[*
|
||||
]]..config.cmd_pat..[[random* _<Username>_: Schau, was passiert!]]
|
||||
end
|
||||
|
||||
fun.command = 'random <Username>'
|
||||
|
||||
function fun:choose_random(user_name, other_user)
|
||||
randoms = {
|
||||
user_name..' schlägt '..other_user..' mit einem stinkenden Fisch.',
|
||||
user_name..' versucht, '..other_user..' mit einem Messer zu töten, bringt sich dabei aber selbst um.',
|
||||
user_name..' versucht, '..other_user..' mit einem Messer zu töten, stolpert aber und schlitzt sich dabei das Knie auf.',
|
||||
user_name..' ersticht '..other_user..'.',
|
||||
user_name..' tritt '..other_user..'.',
|
||||
user_name..' hat '..other_user..' umgebracht! Möge er in der Hölle schmoren!',
|
||||
user_name..' hat die Schnauze voll von '..other_user..' und sperrt ihn in einen Schrank.',
|
||||
user_name..' erwürgt '..other_user..'. BILD sprach als erstes mit der Hand.',
|
||||
user_name..' schickt '..other_user..' nach /dev/null.',
|
||||
user_name..' umarmt '..other_user..'.',
|
||||
user_name..' verschenkt eine Kartoffel an '..other_user..'.',
|
||||
user_name..' melkt '..other_user..'. *muuh* :D',
|
||||
user_name..' wirft einen Gameboy auf '..other_user..'.',
|
||||
user_name..' hetzt die NSA auf '..other_user..'.',
|
||||
user_name..' ersetzt alle CDs von '..other_user..' durch Nickelback-CDs.',
|
||||
}
|
||||
math.randomseed(os.time())
|
||||
math.randomseed(os.time())
|
||||
local random = math.random(15)
|
||||
return randoms[random]
|
||||
end
|
||||
|
||||
function fun:action(msg, config, matches)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
utilities.send_message(self, msg.chat.id, fun.doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local user_name = get_name(msg)
|
||||
local result = fun:choose_random(user_name, input)
|
||||
utilities.send_message(self, msg.chat.id, result)
|
||||
end
|
||||
|
||||
return fun
|
@ -2,16 +2,14 @@ local remind = {}
|
||||
|
||||
local utilities = require('otouto.utilities')
|
||||
|
||||
remind.command = 'remind <duration> <message>'
|
||||
remind.command = 'remind <Länge> <Nachricht>'
|
||||
|
||||
function remind:init(config)
|
||||
self.database.reminders = self.database.reminders or {}
|
||||
|
||||
remind.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('remind', true).table
|
||||
remind.doc = [[```
|
||||
]]..config.cmd_pat..[[remind <duration> <message>
|
||||
Repeats a message after a duration of time, in minutes.
|
||||
```]]
|
||||
remind.doc = [[*
|
||||
]]..config.cmd_pat..[[remind* _<Länge>_ _<Nachricht>_: Erinnert dich in X Minuten an die Nachricht]]
|
||||
end
|
||||
|
||||
function remind:action(msg)
|
||||
@ -44,10 +42,10 @@ function remind:action(msg)
|
||||
self.database.reminders[msg.chat.id_str] = self.database.reminders[msg.chat.id_str] or {}
|
||||
-- Limit group reminders to 10 and private reminders to 50.
|
||||
if msg.chat.type ~= 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 9 then
|
||||
utilities.send_reply(self, msg, 'Sorry, this group already has ten reminders.')
|
||||
utilities.send_reply(self, msg, 'Diese Gruppe hat schon zehn Erinnerungen!')
|
||||
return
|
||||
elseif msg.chat.type == 'private' and utilities.table_size(self.database.reminders[msg.chat.id_str]) > 49 then
|
||||
utilities.send_reply(msg, 'Sorry, you already have fifty reminders.')
|
||||
utilities.send_reply(msg, 'Du hast schon 50 Erinnerungen!')
|
||||
return
|
||||
end
|
||||
-- Put together the reminder with the expiration, message, and message to reply to.
|
||||
@ -56,11 +54,11 @@ function remind:action(msg)
|
||||
message = message
|
||||
}
|
||||
table.insert(self.database.reminders[msg.chat.id_str], reminder)
|
||||
local output = 'I will remind you in ' .. duration
|
||||
local output = 'Ich werde dich in ' .. duration
|
||||
if duration == 1 then
|
||||
output = output .. ' minute!'
|
||||
output = output .. ' Minute erinnern!'
|
||||
else
|
||||
output = output .. ' minutes!'
|
||||
output = output .. ' Minuten erinnern!'
|
||||
end
|
||||
utilities.send_reply(self, msg, output)
|
||||
end
|
||||
@ -75,7 +73,7 @@ function remind:cron()
|
||||
-- If the reminder is past-due, send it and nullify it.
|
||||
-- Otherwise, add it to the replacement table.
|
||||
if time > reminder.time then
|
||||
local output = '*Reminder:*\n"' .. utilities.md_escape(reminder.message) .. '"'
|
||||
local output = '*ERINNERUNG:*\n"' .. utilities.md_escape(reminder.message) .. '"'
|
||||
local res = utilities.send_message(self, chat_id, output, true, nil, true)
|
||||
-- If the message fails to send, save it for later.
|
||||
if not res then
|
||||
|
Reference in New Issue
Block a user