@ -45,6 +45,17 @@ class IRCBot(pydle.Client):
post . solved = True
post . solved = True
post . save ( )
post . save ( )
# Add configured admins as admins
for nick in config . ADMIN_NICKNAMES :
if not IRCSupportOperator . select ( ) . where ( IRCSupportOperator . irc_nick == nick ) :
print ( f " Adding { nick } as an admin " )
i = IRCSupportOperator (
irc_nick = nick ,
is_a_regular = True ,
is_support_admin = True ,
)
i . save ( )
await asyncio . sleep ( 120 )
await asyncio . sleep ( 120 )
async def on_message ( self , target , source , message ) :
async def on_message ( self , target , source , message ) :
@ -54,7 +65,7 @@ class IRCBot(pydle.Client):
print ( f " Target: { target } - Source: { source } - Message: { message } " )
print ( f " Target: { target } - Source: { source } - Message: { message } " )
if self . nickname in message :
if self . nickname in message :
await self . message ( target , f " Sup. I ' m not very helpful yet, but getting there. " )
await self . message ( target , f " Sup. I ' m not very helpful yet, but getting there. Try `.help` " )
# list command to show series of unsolved/active support requests
# list command to show series of unsolved/active support requests
if message in [ " .list " ] :
if message in [ " .list " ] :
@ -126,21 +137,45 @@ class IRCBot(pydle.Client):
# queue command only shows things assigned to you
# queue command only shows things assigned to you
if message in [ " .queue " ] :
if message in [ " .queue " ] :
req = SupportRequest . select ( ) . where (
user = IRCSupportOperator . select ( ) . where ( IRCSupportOperator . irc_nick == source )
IRCSupportOperator . irc_nick == source ,
if not user :
IRCSupportOperator . solved == False
await self . message ( target , " You don ' t have a queue. " )
) . first ( )
return
if req :
reqs = SupportRequest . select ( ) . where (
reqs = [ ]
SupportRequest . assignee == user ,
for i in req :
SupportRequest . solved == False
reqs . append ( i )
)
if reqs :
await self . message ( target , " , " . join ( reqs ) )
await self . message ( target , " , " . join ( reqs ) )
else :
else :
await self . message ( target , " No support requests assigned to you " )
await self . message ( target , " No support requests assigned to you. " )
if message . startswith ( " .promote " ) or message in [ " .promote " ] :
msg = message . split ( )
if not len ( msg ) > 1 :
await self . message ( target , " Invalid arguments. " )
return
promoted_nick = str ( msg [ 1 ] )
if not await self . is_admin ( source ) :
await self . message ( target , " You are not an admin of the support bot. " )
return
if IRCSupportOperator . select ( ) . where ( IRCSupportOperator . irc_nick == promoted_nick ) :
await self . message ( target , " User already exists! " )
return
i = IRCSupportOperator (
irc_nick = promoted_nick ,
is_support_admin = True ,
is_a_regular = True
)
i . save ( )
await self . message ( target , " Added IRC support user: " , irc_nick )
# help command shows available commands
# help command shows available commands
if message in [ " .help " ] :
if message in [ " .help " ] :
await self . message ( target , " `.list`: Show open support tickets on Reddit and synchronized to the database. | `.request x`: Show metadata of support request \" x \" . | `.claim x`: Claim support request \" x \" | `.queue`: Show support requests assigned to you " )
await self . message ( target , " `.list`: Show open support tickets on Reddit and synchronized to the database. | `.request x`: Show metadata of support request \" x \" . | `.claim x`: Claim support request \" x \" | `.queue`: Show support requests assigned to you | `.promote x`: Allow user \" x \" to manage more support duties " )
async def is_admin ( self , nickname ) :
async def is_admin ( self , nickname ) :
admin = False
admin = False
@ -150,6 +185,12 @@ class IRCBot(pydle.Client):
print ( " info: " , info )
print ( " info: " , info )
return admin
return admin
async def is_support_admin ( self , nickname ) :
if IRCSupportOperator . select ( ) . where ( IRCSupportOperator . is_support_admin == True ) :
return True
else :
return False
async def is_registered ( self , nickname ) :
async def is_registered ( self , nickname ) :
irc_nick = IRCSupportOperator . select ( ) . where (
irc_nick = IRCSupportOperator . select ( ) . where (
IRCSupportOperator . irc_nick == nickname
IRCSupportOperator . irc_nick == nickname