riot-translatebot

A simple riot bot which provides Status about Weblate
git clone git://archive.git.mtrnord.blog/Nordgedanken/riot-translatebot.git
Log | Files | Refs | README | LICENSE

commit 9415b6ea82e5bf1d6911b2593ab40a67cb4f8c81
parent e0e5a30156981581b4d7c115a8adad2d029396d2
Author: MTRNord <mtrnord1@gmail.com>
Date:   Mon, 19 Jun 2017 22:32:10 +0200

Only listen to new messages and add basic help command

Signed-off-by: MTRNord <mtrnord1@gmail.com>

Diffstat:
Asrc/commands.js | 9+++++++++
Msrc/index.js | 22++++++++++++++++++----
2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/commands.js b/src/commands.js @@ -0,0 +1,9 @@ +export default class commands { + constructor(client){ + this.client = client; + } + + help = room => { + this.client.sendHtmlNotice(room.roomId, `Help for you!\r\n Commands:\r\n - None`, `Help for you!<br> Commands:<br> - None`).catch(error => console.log(error)); + } +} diff --git a/src/index.js b/src/index.js @@ -1,16 +1,29 @@ import login from './login'; +import CommandHandler from './commands'; const mx = new login; mx.getClient().then(client => { + const ServerStart = new Date; + const commands = new CommandHandler(client); client.on("Room.timeline", (event, room, toStartOfTimeline) => { + if ((ServerStart - event.getDate()) > 0) return; if (toStartOfTimeline) return; if (event.getType() !== "m.room.message") return; if (event.getContent().msgtype !== "m.text") return; - console.log( + if (event.getSender() === "@MTRNord:matrix.org") return; + if (room.roomId !== "!EDuQpgunAOTYiUKIcU:matrix.org" && room.roomId !== "!OYyXUbcTKVsDBUniNn:matrix.eclabs.de") return; + const message = "" + event.getContent().body; + /*console.log( // the room name will update with m.room.name events automatically - "(%s) %s :: %s", room.name, event.getSender(), event.getContent().body + "(%s) %s :: %s", room.name, event.getSender(), message ); + client.sendHtmlNotice(room.roomId, message, message).catch(error => console.log(error));*/ + if (message.includes("!help")){ + console.log( + "(%s) %s :: %s", room.name, event.getSender(), message + ); + commands.help(room); + } }); client.startClient(); -}); - +}); +\ No newline at end of file