Esempio n. 1
0
def sendtoone(who, msg):
	if i18n.isobj(msg):
		msg.setlang(get_userlang(getjid(who)))
		msg = msg.getvalue()

	m = jabber.Message(getjid(who), msg)
	m.setFrom(JID)
	m.setType('chat')
	if conf.general.debug > 1:
		print '...Begin....................', who
	con.send(m)
Esempio n. 2
0
def sendtoone(who, msg):
    if i18n.isobj(msg):
        msg.setlang(get_userlang(getjid(who)))
        msg = msg.getvalue()

    m = jabber.Message(getjid(who), msg)
    m.setFrom(JID)
    m.setType('chat')
    if conf.general.debug > 1:
        print '...Begin....................', who
    con.send(m)
Esempio n. 3
0
def presenceCB(con,prs):
	if conf.general.debug > 3:
		print '>>>', time.strftime('%Y-%m-%d %H:%M:%S'), '[PRESENCE]', prs
	userinfo = conf['userinfo']
	who = unicode(prs.getFrom())
	whoid = getjid(who)
	type = prs.getType()
	# TODO: Try only acking their subscription when they ack ours.
	if type == 'subscribe':
		print ">>> Subscribe from",whoid,
		if isbanned(prs.getFrom().getStripped()):
			print "Banned"
			systoone(who, _('You are banned'))
			boot(prs.getFrom().getStripped())
		elif conf.general['private'] and not isuser(prs.getFrom().getStripped()):
			print "Uninvited"
			systoone(who, _('This is a private conference bot'))
			boot(prs.getFrom().getStripped())
		else:
			print "Accepted"
			con.send(jabber.Presence(to=who, type='subscribed'))
			con.send(jabber.Presence(to=who, type='subscribe'))
			systoall(_('<%s> joins this room.').para(getdisplayname(who)), [who])
			userjid[whoid] = who
	elif type == 'unsubscribe':
		if userjid.has_key(whoid):
			del userjid[whoid]
		boot(prs.getFrom().getStripped())
		print ">>> Unsubscribe from",who
	elif type == 'subscribed':
		if i18n.isobj(welcome):
			wel = welcome.getvalue()
		else:
			wel = welcome
		systoone(who, wel % {'version':version})
		systoone(who, unicode(_('''Topic: %(topic)s
%(lastlog)s''').para({
			"topic" : unicode(conf.general['topic']),
			"lastlog" : unicode("\n".join(lastlog)),
			})  + '\n---------------------------'))
		sendstatus(who, _('here'), _('joining'))
		userjid[whoid] = who
	elif type == 'unsubscribed':
		if userjid.has_key(whoid):
			del userjid[whoid]
		boot(prs.getFrom().getStripped())
		systoall(_('<%s> has left').para(getdisplayname(who)))
	elif type == 'available' or type == None:
		show = prs.getShow()
		if show in [None,'chat','available','online']:
			sendstatus(who, _('here'),prs.getStatus())
		elif show in ['xa']:
			sendstatus(who, _('away'),prs.getStatus())
		elif show in ['away']:
			sendstatus(who, _('away'),prs.getStatus())
		elif show in ['dnd']:
			sendstatus(who, _('away'),prs.getStatus())
		else:
			sendstatus(who, _('away'),show+" [[%s]]" % prs.getStatus())
		userjid[whoid] = who
	elif type == 'unavailable':
		status = prs.getShow()
		sendstatus(who, _('away'),status)
	else:
		if conf.general.debug > 3:
			print ">>> Unknown presence:",who,type
Esempio n. 4
0
def presenceCB(con, prs):
    if conf.general.debug > 3:
        print ">>>", time.strftime("%Y-%m-%d %H:%M:%S"), "[PRESENCE]", prs
    userinfo = conf["userinfo"]
    who = unicode(prs.getFrom())
    whoid = getjid(who)
    type = prs.getType()
    # TODO: Try only acking their subscription when they ack ours.
    if type == "subscribe":
        print ">>> Subscribe from", whoid,
        if isbanned(prs.getFrom().getStripped()):
            print "Banned"
            systoone(who, _("You are banned"))
            boot(prs.getFrom().getStripped())
        elif conf.general["private"] and not isuser(prs.getFrom().getStripped()):
            print "Uninvited"
            systoone(who, _("This is a private conference bot"))
            boot(prs.getFrom().getStripped())
        else:
            print "Accepted"
            con.send(jabber.Presence(to=who, type="subscribed"))
            con.send(jabber.Presence(to=who, type="subscribe"))
            systoall(_("<%s> joins this room.").para(getdisplayname(who)), [who])
            userjid[whoid] = who
    elif type == "unsubscribe":
        if userjid.has_key(whoid):
            del userjid[whoid]
        boot(prs.getFrom().getStripped())
        print ">>> Unsubscribe from", who
    elif type == "subscribed":
        if i18n.isobj(welcome):
            wel = welcome.getvalue()
        else:
            wel = welcome
        systoone(who, wel % {"version": version})
        systoone(
            who,
            unicode(
                _(
                    """Topic: %(topic)s
%(lastlog)s"""
                ).para({"topic": unicode(conf.general["topic"]), "lastlog": unicode("\n".join(lastlog))})
                + "\n---------------------------"
            ),
        )
        sendstatus(who, _("here"), _("joining"))
        userjid[whoid] = who
    elif type == "unsubscribed":
        if userjid.has_key(whoid):
            del userjid[whoid]
        boot(prs.getFrom().getStripped())
        systoall(_("<%s> has left").para(getdisplayname(who)))
    elif type == "available" or type == None:
        show = prs.getShow()
        if show in [None, "chat", "available", "online"]:
            sendstatus(who, _("here"), prs.getStatus())
        elif show in ["xa"]:
            sendstatus(who, _("away"), prs.getStatus())
        elif show in ["away"]:
            sendstatus(who, _("away"), prs.getStatus())
        elif show in ["dnd"]:
            sendstatus(who, _("away"), prs.getStatus())
        else:
            sendstatus(who, _("away"), show + " [[%s]]" % prs.getStatus())
        userjid[whoid] = who
    elif type == "unavailable":
        status = prs.getShow()
        sendstatus(who, _("away"), status)
    else:
        if conf.general.debug > 3:
            print ">>> Unknown presence:", who, type
Esempio n. 5
0
def presenceCB(con, prs):
    if conf.general.debug > 3:
        print '>>>', time.strftime('%Y-%m-%d %H:%M:%S'), '[PRESENCE]', prs
    userinfo = conf['userinfo']
    who = unicode(prs.getFrom())
    whoid = getjid(who)
    type = prs.getType()
    # TODO: Try only acking their subscription when they ack ours.
    if type == 'subscribe':
        print ">>> Subscribe from", whoid,
        if isbanned(prs.getFrom().getStripped()):
            print "Banned"
            systoone(who, _('You are banned'))
            boot(prs.getFrom().getStripped())
        elif conf.general['private'] and not isuser(
                prs.getFrom().getStripped()):
            print "Uninvited"
            systoone(who, _('This is a private conference bot'))
            boot(prs.getFrom().getStripped())
        else:
            print "Accepted"
            con.send(jabber.Presence(to=who, type='subscribed'))
            con.send(jabber.Presence(to=who, type='subscribe'))
            systoall(
                _('<%s> joins this room.').para(getdisplayname(who)), [who])
            userjid[whoid] = who
    elif type == 'unsubscribe':
        if userjid.has_key(whoid):
            del userjid[whoid]
        boot(prs.getFrom().getStripped())
        print ">>> Unsubscribe from", who
    elif type == 'subscribed':
        if i18n.isobj(welcome):
            wel = welcome.getvalue()
        else:
            wel = welcome
        systoone(who, wel % {'version': version})
        systoone(
            who,
            unicode(
                _('''Topic: %(topic)s
%(lastlog)s''').para({
                    "topic": unicode(conf.general['topic']),
                    "lastlog": unicode("\n".join(lastlog)),
                }) + '\n---------------------------'))
        sendstatus(who, _('here'), _('joining'))
        userjid[whoid] = who
    elif type == 'unsubscribed':
        if userjid.has_key(whoid):
            del userjid[whoid]
        boot(prs.getFrom().getStripped())
        systoall(_('<%s> has left').para(getdisplayname(who)))
    elif type == 'available' or type == None:
        show = prs.getShow()
        if show in [None, 'chat', 'available', 'online']:
            sendstatus(who, _('here'), prs.getStatus())
        elif show in ['xa']:
            sendstatus(who, _('away'), prs.getStatus())
        elif show in ['away']:
            sendstatus(who, _('away'), prs.getStatus())
        elif show in ['dnd']:
            sendstatus(who, _('away'), prs.getStatus())
        else:
            sendstatus(who, _('away'), show + " [[%s]]" % prs.getStatus())
        userjid[whoid] = who
    elif type == 'unavailable':
        status = prs.getShow()
        sendstatus(who, _('away'), status)
    else:
        if conf.general.debug > 3:
            print ">>> Unknown presence:", who, type