commit
327ec1c7e8
@ -0,0 +1,93 @@ |
||||
#!/usr/bin/python |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
import brathuhn |
||||
import time |
||||
from datetime import datetime |
||||
import config |
||||
|
||||
############################################## |
||||
# change values to your need |
||||
# DELAY ... time between checks for outdated |
||||
# HOLDBACK ... how long will brathuhn wait |
||||
# to tell someone |
||||
DELAY = 60*60*24 |
||||
HOLDBACK = 60*60*24*7 |
||||
############################################## |
||||
|
||||
store = [] |
||||
|
||||
def tell(msg, args): |
||||
global store |
||||
|
||||
if( len(args) <= 2): |
||||
brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" nick text",'groupchat') |
||||
return |
||||
|
||||
userJID = brathuhn.getUsers().items() |
||||
for a in userJID: |
||||
if( args[1] == a[0].getResource()): |
||||
brathuhn.sendMsg(brathuhn.ROOM,"User "+args[1]+" is already here, tell them yourself!",'groupchat') |
||||
return |
||||
|
||||
body = unicode(msg.getBody()) |
||||
spl = body.split(' ', 2) |
||||
message = spl[2] |
||||
nick = spl[1] |
||||
origin = msg.getFrom().getResource() |
||||
store.append( (nick, message, origin, datetime.today()) ) |
||||
brathuhn.sendMsg(brathuhn.ROOM,origin+": will do!",'groupchat') |
||||
|
||||
def tellCB(nick, msg, status): |
||||
global store |
||||
|
||||
if(status != brathuhn.STATUS_JOIN): |
||||
return |
||||
|
||||
|
||||
user = nick.getResource() |
||||
rem = [] |
||||
for l in store: |
||||
if(l[0] == unicode(user)): |
||||
timestamp = "{:02}:{:02}, {}-{:02}-{:02}".format(l[3].hour, l[3].minute, l[3].year, l[3].month, l[3].day) |
||||
brathuhn.sendMsg(brathuhn.ROOM,(l[0]+": User "+l[2]+" told me at "+timestamp+" to tell you: \""+l[1]+"\""),'groupchat') |
||||
rem.append(l) |
||||
|
||||
for r in rem: |
||||
store.remove(r) |
||||
|
||||
def cleartell(): |
||||
global store |
||||
now = datetime.today() |
||||
rem = [] |
||||
for l in store: |
||||
if(now - l[3] < HOLDBACK): |
||||
rem.append(l) |
||||
for r in rem: |
||||
store.remove(r) |
||||
|
||||
brathuhn.callAt(cleartell, time.time()+DELAY, []) |
||||
|
||||
############################################## |
||||
|
||||
brathuhn.addCommand("tell","Usage: !tell nick text", tell) |
||||
brathuhn.addStatusListener(tellCB) |
||||
brathuhn.callAt(cleartell, time.time()+DELAY, []) |
||||
|
||||
############################################## |
||||
|
||||
#def flushtell(msg, args): |
||||
# global store |
||||
# store = [] |
||||
# |
||||
#brathuhn.addCommand("flush","Usage: !flush ", flushtell) |
||||
|
||||
#def showtell(msg, args): |
||||
# #global store |
||||
# |
||||
# for l in store: |
||||
# timestamp = "{:02}:{:02}, {}-{:02}-{:02}".format(l[3].hour, l[3].minute, l[3].year, l[3].month, l[3].day) |
||||
# brathuhn.sendMsg(brathuhn.ROOM,(l[2]+" -> "+ l[0]+"; "+l[1]+"; "+timestamp),'groupchat') |
||||
# |
||||
#brathuhn.addCommand("show","Usage: !show ", showtell) |
||||
|
||||
Loading…
Reference in new issue