More code

This commit is contained in:
Tulir Asokan
2017-11-21 00:09:39 +02:00
parent 217017099a
commit 5ef0a202a2
9 changed files with 145 additions and 116 deletions
+2 -34
View File
@@ -45,11 +45,7 @@ cancel - Cancel an ongoing action (such as login).
login <phone> - Request an authentication code.
logout - Log out from Telegram.
api <method> <args> - Call a Telegram API method. Args is always a JSON object. Disabled by default.
Temporary commands that will be replaced with better commands in the future:
createRoom <type> <id> - Create a portal room. <type> is user, chat or channel and <id> is the numeric ID of the Telegram chat.
syncUsers <type> <id> - Sync user info and join status in the given portal. Same arguments as createRoom.`)
api <method> <args> - Call a Telegram API method. Args is always a JSON object. Disabled by default.`)
}
@@ -143,34 +139,6 @@ commands.logout = async (sender, args, reply) => {
}
}
const TelegramPeer = require("./telegram-peer")
const Portal = require("./portal")
commands.createRoom = async (sender, args, reply, app) => {
let peer = new TelegramPeer(args[0], +args[1])
const portal = await app.getPortalByPeer(peer)
const roomID = await portal.createMatrixRoom(sender.telegramPuppet)
if (!roomID) {
reply("Failed to create room.")
return
}
await app.botIntent.invite(roomID, sender.userID)
reply(`Created room ${roomID} and invited ${sender.userID}`)
}
commands.syncUsers = async (sender, args, reply, app) => {
let peer = new TelegramPeer(args[0], +args[1])
const portal = await app.getPortalByPeer(peer)
try {
await portal.syncTelegramUsers(sender.telegramPuppet)
reply("Users synchronized successfully.")
} catch (err) {
reply(`Failed to sync users: ${err}`)
console.error(err)
console.error(err.stack)
}
}
//////////////////////////////
// General command handlers //
//////////////////////////////
@@ -181,7 +149,7 @@ commands.syncUsers = async (sender, args, reply, app) => {
////////////////////////////
commands.api = async (sender, args, reply, app) => {
if (!app.config.telegram.allow_direct_api_calls) {
if (!app.config.bridge.commands.allow_direct_api_calls) {
reply("Direct API calls are forbidden on this mautrix-telegram instance.")
return
}