From 0238610cd1202163c74c2dfadc34ba38133dfab7 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 29 Jan 2019 02:05:39 +0530 Subject: [PATCH] Add /list --- bot/bot.py | 10 +++++++++- chat_mod/init.lua | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index d6b6f22..8c9f44f 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -5,7 +5,7 @@ import logging import requests import re from emoji import demojize -from telegram.ext import Updater, MessageHandler, Filters +from telegram.ext import Updater, CommandHandler, MessageHandler, Filters logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \ %(message)s', level=logging.INFO) @@ -87,7 +87,15 @@ def message_handling(bot, update): data=params) +def list_cmd(bot, update): + if update.message.chat.id in config.groups: + params = {"message": "list"} + requests.post("http://localhost:" + str(config.port) + "/post", + data=params) + + updater = Updater(token=config.api_key) dispatcher = updater.dispatcher +dispatcher.add_handler(CommandHandler('list', list_cmd)) dispatcher.add_handler(MessageHandler(Filters.all, message_handling)) updater.start_polling() diff --git a/chat_mod/init.lua b/chat_mod/init.lua index e8a7285..15e86e4 100644 --- a/chat_mod/init.lua +++ b/chat_mod/init.lua @@ -2,7 +2,17 @@ local http_api = minetest.request_http_api() function send_messages(res) for message in string.gmatch(res["data"], "[^\n]+") do - minetest.chat_send_all(message) + if message == "list" then + local x = minetest.get_connected_players() + local text = "List of Players:\n" + for j, i in ipairs(x) do + local text = text .. i.get_player_name(i) + end + http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode", + post_data = {message = text}}) + else + minetest.chat_send_all(message) + end end end