jabber_mirror: Factor out jid_to_zulip and use str.rpartition
(imported from commit 435f076d7125676b5b964c73ec1e3753496c32af)
This commit is contained in:
		
							parent
							
								
									36f8957b36
								
							
						
					
					
						commit
						e7a1d3b0d7
					
				
					 1 changed files with 7 additions and 7 deletions
				
			
		|  | @ -33,7 +33,10 @@ import os, sys, zulip, getpass | |||
| import re | ||||
| 
 | ||||
| def room_to_stream(room): | ||||
|     return str(room).split("@")[0] | ||||
|     return str(room).rpartition("@")[0] | ||||
| 
 | ||||
| def jid_to_zulip(jid): | ||||
|     return "%s@%s" % (str(jid).rpartition("@")[0], options.zulip_domain) | ||||
| 
 | ||||
| class JabberToZulipBot(ClientXMPP): | ||||
|     def __init__(self, nick, password, rooms, openfire=False): | ||||
|  | @ -83,8 +86,8 @@ class JabberToZulipBot(ClientXMPP): | |||
|     def private(self, msg): | ||||
|         if msg["from"] == self.jid or msg['thread'] == u'\u1B80': | ||||
|             return | ||||
|         sender = self.jid_to_zulip(msg["from"]) | ||||
|         recipient = self.jid_to_zulip(msg["to"]) | ||||
|         sender = jid_to_zulip(msg["from"]) | ||||
|         recipient = jid_to_zulip(msg["to"]) | ||||
| 
 | ||||
|         zulip_message = dict( | ||||
|             sender = sender, | ||||
|  | @ -105,7 +108,7 @@ class JabberToZulipBot(ClientXMPP): | |||
|             subject = "(no topic)" | ||||
|         stream = room_to_stream(msg.get_mucroom()) | ||||
|         jid = self.nickname_to_jid(msg.get_mucroom(), msg.get_mucnick()) | ||||
|         sender = self.jid_to_zulip(jid) | ||||
|         sender = jid_to_zulip(jid) | ||||
|         zulip_message = dict( | ||||
|             forged = "yes", | ||||
|             sender = sender, | ||||
|  | @ -118,9 +121,6 @@ class JabberToZulipBot(ClientXMPP): | |||
|         if ret.get("status") != "success": | ||||
|             logging.error(ret) | ||||
| 
 | ||||
|     def jid_to_zulip(self, jid): | ||||
|         return "%s@%s" % (str(jid).split("@")[0], options.zulip_domain) | ||||
| 
 | ||||
|     def nickname_to_jid(self, room, nick): | ||||
|         jid = self.plugin['xep_0045'].getJidProperty(room, nick, "jid") | ||||
|         if (jid is None or jid == ''): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zev Benjamin
						Zev Benjamin