@ -69,6 +69,7 @@ class DiscordClient(discord.Client):
self . logger . info ( ' Logged in as {0} ' . format ( self . user . name ) )
async def on_message ( self , message ) :
await self . _process_new_member ( message )
await self . _process_announcement ( message )
server = message . server . id if message . server else None
for pattern , action in self . supported_commands :
@ -79,9 +80,32 @@ class DiscordClient(discord.Client):
if cmd == message . content :
await self . send_message ( message . channel , resp . format ( user = message . author . mention ) )
async def _process_new_member ( self , message ) :
new_members_channel = self . config [ ' Discord ' ] . get ( ' new_members_channel ' )
info_channel = self . config [ ' Discord ' ] . get ( ' info_channel ' )
welcome_channel = self . config [ ' Discord ' ] . get ( ' welcome_channel ' )
welcome_pattern = self . config [ ' Discord ' ] . get ( ' welcome_pattern ' )
if not message . channel or not message . server :
return
if message . channel . id != new_members_channel :
return
info_channel = [ c for c in message . server . channels if c . id == info_channel ]
if info_channel :
info_channel = info_channel [ 0 ]
else :
return
welcome_channel = discord . Object ( welcome_channel )
try :
await self . send_message ( welcome_channel , welcome_pattern . format (
user = message . author . mention , info_channel = info_channel . mention ) )
except discord . errors . Forbidden :
pass
async def _process_announcement ( self , message ) :
announcer = self . config [ ' Discord ' ] . get ( ' announcer ' )
channels = self . config [ ' Discord ' ] . get ( ' announcement_channels ' ) . split ( ' , ' )
if not message . author or not message . channel :
return
if message . author . id != announcer or message . channel . id not in channels :
return
after = datetime . datetime . utcnow ( ) - datetime . timedelta ( minutes = 5 )