Channel: Das Plugin nutzt jetzt matches, wobei sich der Code verringert und das ganze jetzt übersichtlicher aussieht. InlineKeyboards mit URL-Buttons werden jetzt unterstützt und können an Gruppen gesendet werden! Yay!
This commit is contained in:
		| @@ -5,30 +5,28 @@ local utilities = require('otouto.utilities') | |||||||
|  |  | ||||||
| channel.command = 'ch <Kanal> \\n <Nachricht>' | channel.command = 'ch <Kanal> \\n <Nachricht>' | ||||||
| channel.doc = [[* | channel.doc = [[* | ||||||
| /ch*_ <Kanal>_ | /ch*_ <Kanal>_|_[Inline-Keyboard]_ | ||||||
| _<Nachricht>_ | _<Nachricht>_ | ||||||
|  |  | ||||||
| Sendet eine Nachricht in den Kanal. Der Kanal kann per Username oder ID bestimmt werden, Markdown wird unterstützt. Du musst Administrator oder Besitzer des Kanals sein. | Sendet eine Nachricht in den Kanal. Der Kanal kann per Username oder ID bestimmt werden, Markdown wird unterstützt. Du musst Administrator oder Besitzer des Kanals sein. | ||||||
|   |   | ||||||
| Markdown-Syntax: | Inline-Keyboards sind OPTIONAL, in dem Falle einfach den Strich weglassen. Es werden NUR URL-Buttons unterstützt! Eine Beispielsyntax für einen Button findest du [auf GitHub](https://gist.githubusercontent.com/Brawl345/e671b60e24243da81934/raw/Inline-Keyboard.json). | ||||||
|  *Fetter Text* |  | ||||||
|  _Kursiver Text_ |  | ||||||
|  [Text](URL) |  | ||||||
|  `Inline-Codeblock` |  | ||||||
|  ```Größere Code-Block über mehrere Zeilen``` |  | ||||||
|   |   | ||||||
| *Der Kanalname muss mit einem @ beginnen!*]] | *Der Kanalname muss mit einem @ beginnen!*]] | ||||||
|  |  | ||||||
| function channel:init(config) | function channel:init(config) | ||||||
| 	channel.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('ch', true).table |     channel.triggers = { | ||||||
|  | 	  "^/ch @([A-Za-z0-9-_-]+)|(.+)\n(.*)", | ||||||
|  | 	  "^/ch @([A-Za-z0-9-_-]+)\n(.*)" | ||||||
|  | 	} | ||||||
| end | end | ||||||
|  |  | ||||||
| function channel:action(msg, config) | function channel:action(msg, config) | ||||||
|   local input = utilities.input(msg.text) |   local input = utilities.input(msg.text) | ||||||
|   local output |   local output | ||||||
| 	if input then |   local chat_id = '@'..matches[1] | ||||||
| 		local chat_id = utilities.get_word(input, 1) |   local admin_list, gca_results = utilities.get_chat_administrators(self, chat_id) | ||||||
| 		local admin_list, t = bindings.getChatAdministrators(self, { chat_id = chat_id } ) |  | ||||||
|   if admin_list then |   if admin_list then | ||||||
| 	local is_admin = false | 	local is_admin = false | ||||||
| 	for _, admin in ipairs(admin_list.result) do | 	for _, admin in ipairs(admin_list.result) do | ||||||
| @@ -37,25 +35,34 @@ function channel:action(msg, config) | |||||||
| 	  end | 	  end | ||||||
| 	end | 	end | ||||||
| 	if is_admin then | 	if is_admin then | ||||||
| 				local text = input:match('\n(.+)') | 	  if matches[3] then | ||||||
| 				if text then | 	    text = matches[3] | ||||||
| 					local success, result = utilities.send_message(self, chat_id, text, true, nil, true) | 		reply_markup = matches[2] | ||||||
|  | 		-- Yeah, channels don't allow this buttons currently, but when they're ready | ||||||
|  | 		-- this plugin will also be ready :P | ||||||
|  | 		-- Also, URL buttons work!? Maybe beta? | ||||||
|  | 		if reply_markup:match('"callback_data":"') then | ||||||
|  | 		  utilities.send_reply(self, msg, 'callback_data ist in Buttons nicht erlaubt.') | ||||||
|  | 		  return | ||||||
|  | 		elseif reply_markup:match('"switch_inline_query":"') then | ||||||
|  | 		  utilities.send_reply(self, msg, 'switch_inline_query ist in Buttons nicht erlaubt.') | ||||||
|  | 		  return | ||||||
|  | 		end | ||||||
|  | 	  else | ||||||
|  | 	    text = matches[2] | ||||||
|  | 		reply_markup = nil | ||||||
|  | 	  end | ||||||
|  | 	  local success, result = utilities.send_message(self, chat_id, text, true, nil, true, reply_markup) | ||||||
| 	  if success then | 	  if success then | ||||||
| 	    output = 'Deine Nachricht wurde versendet!' | 	    output = 'Deine Nachricht wurde versendet!' | ||||||
| 	  else | 	  else | ||||||
| 	    output = 'Sorry, ich konnte deine Nachricht nicht senden.\n`' .. result.description .. '`' | 	    output = 'Sorry, ich konnte deine Nachricht nicht senden.\n`' .. result.description .. '`' | ||||||
| 	  end | 	  end | ||||||
| 				else |  | ||||||
| 					output = 'Bitte gebe deine Nachricht ein. Markdown wird unterstützt.' |  | ||||||
| 				end |  | ||||||
|     else |     else | ||||||
| 	  output = 'Es sieht nicht so aus, als wärst du der Administrator dieses Kanals.' | 	  output = 'Es sieht nicht so aus, als wärst du der Administrator dieses Kanals.' | ||||||
|     end |     end | ||||||
|   else |   else | ||||||
| 			output = 'Sorry, ich konnte die Administratorenliste nicht abrufen. Falls du den Kanalnamen benutzt: Beginnt er mit einem @?\n`' .. t.description .. '`' | 	output = 'Sorry, ich konnte die Administratorenliste nicht abrufen!\n`'..gca_results.description..'`' | ||||||
| 		end |  | ||||||
| 	else |  | ||||||
| 		output = channel.doc |  | ||||||
|   end |   end | ||||||
|   utilities.send_reply(self, msg, output, true) |   utilities.send_reply(self, msg, output, true) | ||||||
| end | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andreas Bielawski
					Andreas Bielawski