Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
Move PlayerXmppPlugin to stanzas
Browse files Browse the repository at this point in the history
Also remove PlayerXmppPlugin from echelon, as it apparently wasn't used
there.
  • Loading branch information
Dunedan committed Aug 31, 2017
1 parent d460b08 commit 9b3c59c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 41 deletions.
21 changes: 1 addition & 20 deletions xpartamupp/echelon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import sleekxmpp
from sleekxmpp.stanza import Iq
from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin, ET
from sleekxmpp.xmlstream import register_stanza_plugin
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.xmlstream.matcher import StanzaPath
import sqlalchemy
Expand Down Expand Up @@ -477,24 +477,6 @@ def get_num_players(raw_game_report):
return -1


class PlayerXmppPlugin(ElementBase):
"""Class for custom player stanza extension."""

name = 'query'
namespace = 'jabber:iq:player'
interfaces = {'game', 'online'}
sub_interfaces = interfaces
plugin_attrib = 'player'

def add_player_online(self, player):
"""Add a player to the extension.
Arguments:
player (str): JID of the player to add
"""
self.xml.append(ET.fromstring("<player>%s</player>" % player))


class EcheLOn(sleekxmpp.ClientXMPP):
"""Main class which handles IQ data and sends new data."""

Expand All @@ -511,7 +493,6 @@ def __init__(self, sjid, password, room, nick):
# stanza
self.nicks = {}

register_stanza_plugin(Iq, PlayerXmppPlugin)
register_stanza_plugin(Iq, BoardListXmppPlugin)
register_stanza_plugin(Iq, GameReportXmppPlugin)
register_stanza_plugin(Iq, ProfileXmppPlugin)
Expand Down
19 changes: 19 additions & 0 deletions xpartamupp/stanzas.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ def get_game(self):
return data


class PlayerXmppPlugin(ElementBase):
"""Class for custom player stanza extension."""

name = 'query'
namespace = 'jabber:iq:player'
interfaces = {'online'}
sub_interfaces = interfaces
plugin_attrib = 'player'

def add_player_online(self, player):
"""Add a player to the extension.
Arguments:
player (str): JID of the player to add
"""
self.xml.append(ET.fromstring("<online>%s</online>" % player))


class ProfileXmppPlugin(ElementBase):
"""Class for custom profile."""

Expand Down
23 changes: 2 additions & 21 deletions xpartamupp/xpartamupp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

import sleekxmpp
from sleekxmpp.stanza import Iq
from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin, ET
from sleekxmpp.xmlstream import register_stanza_plugin
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.xmlstream.matcher import StanzaPath

from xpartamupp.stanzas import (BoardListXmppPlugin, GameListXmppPlugin, GameReportXmppPlugin,
ProfileXmppPlugin)
PlayerXmppPlugin, ProfileXmppPlugin)


class Games(object):
Expand Down Expand Up @@ -92,25 +92,6 @@ def change_game_state(self, jid, data):
self.games[jid]['startTime'] = str(round(time.time()))


class PlayerXmppPlugin(ElementBase):
"""Class for custom player stanza extension."""

name = 'query'
namespace = 'jabber:iq:player'
interfaces = {'online'}
sub_interfaces = interfaces
plugin_attrib = 'player'

def add_player_online(self, player):
"""Add a player to the extension.
Arguments:
player (str): JID of the player to add
"""
self.xml.append(ET.fromstring("<online>%s</online>" % player))


class XpartaMuPP(sleekxmpp.ClientXMPP):
"""Main class which handles IQ data and sends new data."""

Expand Down

0 comments on commit 9b3c59c

Please sign in to comment.