Skip to content

Commit

Permalink
whatsapp.py 0.2: adapt to new yowsup version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafflationist authored and flashcode committed Jul 30, 2022
1 parent c46d70a commit 1a0c26d
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions python/whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

#
# whatsapp protocol for WeeChat.
# (this script requires WeeChat 0.3.0 (or newer) and the yowsup library)
# (this script requires WeeChat 2.9 (or newer) and the yowsup library)
#
# For help, see /help whatsapp
# Happy chat, enjoy :)
#
# History:
# 2022-07-17, Marcel Robohm <[email protected]>:
# version 0.2: adapt to new yowsup version
# 2015-12-30, Jochen Sprickerhof <[email protected]>:
# version 0.1: Reworked for Whatsapp
# 2013-09-30, Nils Görs <freenode.nils_2>:
Expand Down Expand Up @@ -90,7 +92,7 @@

SCRIPT_NAME = "whatsapp"
SCRIPT_AUTHOR = "Jochen Sprickerhof <[email protected]>"
SCRIPT_VERSION = "0.1"
SCRIPT_VERSION = "0.2"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Whatsapp protocol for WeeChat"
SCRIPT_COMMAND = SCRIPT_NAME
Expand All @@ -103,17 +105,16 @@
import weechat
except:
print("This script must be run under WeeChat.")
print("Get WeeChat now at: http://www.weechat.org/")
print("Get WeeChat now at: https://weechat.org/")
import_ok = False

try:
from yowsup.common import YowConstants
from yowsup.layers import YowLayerEvent
from yowsup.layers.auth import AuthError
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
from yowsup.layers.network import YowNetworkLayer
from yowsup.layers.protocol_contacts.protocolentities.iq_statuses_get import GetStatusesIqProtocolEntity
from yowsup.layers.protocol_contacts.protocolentities.iq_statuses_result import ResultStatusesIqProtocolEntity
from yowsup.layers.protocol_profiles.protocolentities.iq_statuses_get import GetStatusesIqProtocolEntity
from yowsup.layers.protocol_profiles.protocolentities.iq_statuses_result import ResultStatusesIqProtocolEntity
from yowsup.layers.protocol_iq import YowIqProtocolLayer
from yowsup.layers.protocol_iq.protocolentities.iq import IqProtocolEntity
from yowsup.layers.protocol_iq.protocolentities.iq_ping import PingIqProtocolEntity
Expand Down Expand Up @@ -631,15 +632,7 @@ def getDownloadableMediaMessageBody(self, message):

def recv(self):
""" Receive something from whatsapp server. """
try:
self.getStack().getLayer(0).handle_read()
except AuthError as e:
weechat.prnt('', '%s: Error from server: %s' %(SCRIPT_NAME, e))
self.disconnect()
if weechat.config_boolean(self.options['autoreconnect']):
autoreconnect_delay = 30
weechat.command('', '/wait %s /%s connect %s' %
(autoreconnect_delay, SCRIPT_COMMAND, self.name))
self.getStack().getLayer(0).handle_read()

def recv_message(self, buddy, message):
""" Receive a message from buddy. """
Expand Down Expand Up @@ -1550,16 +1543,16 @@ def whatsapp_completion_servers(data, completion_item, buffer, completion):
""" Completion with whatsapp server names. """
global whatsapp_servers
for server in whatsapp_servers:
weechat.hook_completion_list_add(completion, server.name,
0, weechat.WEECHAT_LIST_POS_SORT)
weechat.completion_list_add(completion, server.name,
0, weechat.WEECHAT_LIST_POS_SORT)
return weechat.WEECHAT_RC_OK

def whatsapp_completion_jid_aliases(data, completion_item, buffer, completion):
""" Completion with whatsapp alias names. """
global whatsapp_jid_aliases
for alias, jid in sorted(whatsapp_jid_aliases.items()):
weechat.hook_completion_list_add(completion, alias,
0, weechat.WEECHAT_LIST_POS_SORT)
weechat.completion_list_add(completion, alias,
0, weechat.WEECHAT_LIST_POS_SORT)
return weechat.WEECHAT_RC_OK

# ==================================[ fd ]====================================
Expand Down

0 comments on commit 1a0c26d

Please sign in to comment.