mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
Cleaner code for optional parameters
This commit is contained in:
parent
79f3a00415
commit
dd98853861
1 changed files with 25 additions and 20 deletions
35
tipbot.py
35
tipbot.py
|
@ -152,6 +152,14 @@ def Part(chan):
|
||||||
def Who(chan):
|
def Who(chan):
|
||||||
SendIRC ( 'WHO ' + chan)
|
SendIRC ( 'WHO ' + chan)
|
||||||
|
|
||||||
|
def IsParamPresent(parms,idx):
|
||||||
|
return len(parms) > idx
|
||||||
|
|
||||||
|
def GetParam(parms,idx):
|
||||||
|
if IsParamPresent(parms,idx):
|
||||||
|
return parms[idx]
|
||||||
|
return None
|
||||||
|
|
||||||
def CheckRegistered(nick,ifyes,yesdata,ifno,nodata):
|
def CheckRegistered(nick,ifyes,yesdata,ifno,nodata):
|
||||||
if nick not in calltable:
|
if nick not in calltable:
|
||||||
calltable[nick] = []
|
calltable[nick] = []
|
||||||
|
@ -305,11 +313,10 @@ def Rain(nick,data):
|
||||||
except Exception,e:
|
except Exception,e:
|
||||||
SendTo(sendto, "Usage: rain amount [users]")
|
SendTo(sendto, "Usage: rain amount [users]")
|
||||||
return
|
return
|
||||||
|
users = GetParam(data,2)
|
||||||
|
if users:
|
||||||
try:
|
try:
|
||||||
if data[2] == None:
|
users=long(users)
|
||||||
users = None
|
|
||||||
else:
|
|
||||||
users=long(data[2])
|
|
||||||
except Exception,e:
|
except Exception,e:
|
||||||
SendTo(sendto, "Usage: rain amount [users]")
|
SendTo(sendto, "Usage: rain amount [users]")
|
||||||
return
|
return
|
||||||
|
@ -398,10 +405,10 @@ def IsValidAddress(address):
|
||||||
|
|
||||||
def Withdraw(nick,data):
|
def Withdraw(nick,data):
|
||||||
address=data[0]
|
address=data[0]
|
||||||
amount=data[1]
|
|
||||||
if not IsValidAddress(address):
|
if not IsValidAddress(address):
|
||||||
SendTo(nick, "Invalid address")
|
SendTo(nick, "Invalid address")
|
||||||
return
|
return
|
||||||
|
amount = GetParam(data,1)
|
||||||
if amount:
|
if amount:
|
||||||
try:
|
try:
|
||||||
famount=float(amount)
|
famount=float(amount)
|
||||||
|
@ -994,15 +1001,14 @@ while True:
|
||||||
CheckRegistered(GetNick(who),GetBalance,[sendto],SendTo,"You must be registered with Freenode to query balance")
|
CheckRegistered(GetNick(who),GetBalance,[sendto],SendTo,"You must be registered with Freenode to query balance")
|
||||||
elif cmd[0] == 'tip':
|
elif cmd[0] == 'tip':
|
||||||
if len(cmd) == 3:
|
if len(cmd) == 3:
|
||||||
CheckRegistered(GetNick(who),Tip,[sendto,cmd[1],cmd[2]],SendTo,"You must be registered with Freenode to tip")
|
parms=[sendto]
|
||||||
|
parms.extend(cmd[1:])
|
||||||
|
CheckRegistered(GetNick(who),Tip,parms,SendTo,"You must be registered with Freenode to tip")
|
||||||
else:
|
else:
|
||||||
SendTo(GetNick(who), "Usage: !tip nick amount");
|
SendTo(GetNick(who), "Usage: !tip nick amount");
|
||||||
elif cmd[0] == 'withdraw':
|
elif cmd[0] == 'withdraw':
|
||||||
if len(cmd) == 2 or len(cmd) == 3:
|
if len(cmd) == 2 or len(cmd) == 3:
|
||||||
amount = None
|
CheckRegistered(GetNick(who),Withdraw,cmd[1:],SendTo,"You must be registered with Freenode to withdraw")
|
||||||
if len(cmd) == 3:
|
|
||||||
amount = cmd[2]
|
|
||||||
CheckRegistered(GetNick(who),Withdraw,[cmd[1],amount],SendTo,"You must be registered with Freenode to withdraw")
|
|
||||||
else:
|
else:
|
||||||
SendTo(GetNick(who), "Usage: !withdraw address");
|
SendTo(GetNick(who), "Usage: !withdraw address");
|
||||||
elif cmd[0] == 'info':
|
elif cmd[0] == 'info':
|
||||||
|
@ -1010,10 +1016,9 @@ while True:
|
||||||
elif cmd[0] == 'rain':
|
elif cmd[0] == 'rain':
|
||||||
if chan[0] == '#':
|
if chan[0] == '#':
|
||||||
if len(cmd) == 2 or len(cmd) == 3:
|
if len(cmd) == 2 or len(cmd) == 3:
|
||||||
users = None
|
parms=[chan]
|
||||||
if len(cmd) == 3:
|
parms.extend(cmd[1:])
|
||||||
users = cmd[2]
|
CheckRegistered(GetNick(who),Rain,parms,SendTo,"You must be registered with Freenode to rain")
|
||||||
CheckRegistered(GetNick(who),Rain,[chan,cmd[1],users],SendTo,"You must be registered with Freenode to rain")
|
|
||||||
else:
|
else:
|
||||||
SendTo(sendto, "Usage: !rain amount [users]");
|
SendTo(sendto, "Usage: !rain amount [users]");
|
||||||
else:
|
else:
|
||||||
|
@ -1035,7 +1040,7 @@ while True:
|
||||||
CheckAdmin(GetNick(who),DumpUsers,None,SendTo,"You must be admin")
|
CheckAdmin(GetNick(who),DumpUsers,None,SendTo,"You must be admin")
|
||||||
elif cmd[0] == 'show_activity':
|
elif cmd[0] == 'show_activity':
|
||||||
if len(cmd)==3:
|
if len(cmd)==3:
|
||||||
CheckAdmin(GetNick(who),ShowActivity,[cmd[1],cmd[2]],SendTo,"You must be admin")
|
CheckAdmin(GetNick(who),ShowActivity,cmd[1:],SendTo,"You must be admin")
|
||||||
else:
|
else:
|
||||||
SendTo(sendto,"Usage: show_activity channel nick")
|
SendTo(sendto,"Usage: show_activity channel nick")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue