Levak / warfacebot

WarfaceBot, a headless XMPP client for Warface (FPS game)
GNU Affero General Public License v3.0
94 stars 73 forks source link

Can we use NodeJS and Warfacebot DBus API together? #59

Closed shockwaves closed 6 years ago

shockwaves commented 7 years ago

Is it possible make use warfacebot application with NodeJS engine and make event driven exchange with it?

Levak commented 7 years ago

Hi,

I am afraid I do not totally get your question nor the issue title, so let me rephrase what I understand:

Is there an API for NodeJS like the one currently available for DBus?

Answer, no, mainly because I do not know NodeJS, at all.

At the moment, the DBus API is in a proof-of-concept state. It lacks some callback mechanism and error feedback to be 100% reliable. Nevertheless, it works well with a Python stack, like Flask and DBus Python libraries.

shockwaves commented 7 years ago

Good I'll try to test. I pointed an NodeJS as an example which has the ability to use Dbus or Buffers. Before these I tried parse stdout from wb process and same way interact with the command line for call CMD commands. But its ugly way for me =)

shockwaves commented 7 years ago

it works well with a Python stack, like Flask and DBus Python libraries.

can you show me an example?

Levak commented 7 years ago

can you show me an example?

I still didn't take the time to create small examples because of it still being a POC.

Here is a very naive echo python script:

#! /usr/bin/env python3
import dbus
import gi
from gi.repository import GObject

loop = GObject.MainLoop()
bot_realm = 'eu'
bot_dbus_id = 'TODO'
bus = dbus.SessionBus(mainloop=loop)

watch_bot = dbus.bus.NameOwnerWatch(bus, 'org.levak.Warfacebot', bot_changed)
def bot_changed(owner):
  bot_obj = self.bus.get_object('org.levak.Warfacebot.' + bot_realm + '.' + bot_dbus_id, '/org/levak/Warfacebot')
  bot_iface = dbus.Interface(bot_obj, 'org.levak.Warfacebot')
  bot_iface.connect_to_signal('BuddyMessage', bot_on_msg)

def bot_on_msg(Nick, Msg):
  nick, msg = str(nick), str(msg)
  print(nick, "whispers:", msg)
  bot_iface.BuddyWhisper(nick, "hey, sup?")

loop.run()

It connects to DBus, waits for the bot to be on it (connects after join_channel) and then waits for whisper events. Once a whisper is received, prints the message in term and then replies to it.

I have no idea if it's also that dead simple using NodeJS.

bosoi911 commented 7 years ago

Levak.... help me pls...
d2d12c4eb86b46cca40b275a7f0d9715

Levak commented 7 years ago

Levak.... help me pls...

Please do not hijack other threads with your own, different, problems. To answer you, you just have to edit cfg/server/eu.cfg with the correct game version.