55from slack import methods
66
77from .message_templates .tech import TechTerms
8+ from .utils import BOT_URL
89
910logger = logging .getLogger (__name__ )
1011
@@ -15,73 +16,74 @@ def create_endpoints(plugin):
1516 plugin .on_message (".*\!tech" , tech_tips )
1617 plugin .on_message (".*\<\!here\>" , here_bad )
1718 plugin .on_message (".*\<\!channel\>" , here_bad )
18- plugin .on_message (".*@here" , here_bad )
19- plugin .on_message (".*@channel" , here_bad )
2019 plugin .on_message (".*\!pybot" , advertise_pybot )
2120
2221
2322def not_bot_message (event : Message ):
24- return ('message' not in event or
25- 'subtype' not in event ['message' ] or
26- event ['message' ]['subtype' ] != 'bot_message' )
23+ return (
24+ 'message' not in event
25+ or 'subtype' not in event ['message' ]
26+ or event ['message' ]['subtype' ] != 'bot_message'
27+ )
2728
2829
2930def not_bot_delete (event : Message ):
3031 return 'previous_message' in event and 'bot_id' not in event ['previous_message' ]
3132
3233
3334async def advertise_pybot (event : Message , app : SirBot ):
34- BOT_URL = 'https://github.com/OperationCode/operationcode-pybot'
35- response = {'channel' : event ['channel' ],
36- 'text' : f'OC-Community-Bot is a community led project'
37- f'\n <{ BOT_URL } |source> ' }
35+ response = dict (
36+ channel = event ['channel' ],
37+ text = f'OC-Community-Bot is a community led project\n <{ BOT_URL } |source> '
38+ )
39+
3840 await app .plugins ["slack" ].api .query (methods .CHAT_POST_MESSAGE , data = response )
3941
4042
41- async def here_bad (event : Message , app : SirBot ):
43+ async def here_bad (event : Message , app : SirBot ) -> None :
4244 if 'channel_type' in event and event ['channel_type' ] != 'im' :
43- response = {'channel' : event ['channel' ],
44- 'text' : f'<@{ event ["user" ]} > - you are a very bad person for using that command' }
45- await app .plugins ["slack" ].api .query (methods .CHAT_POST_MESSAGE , data = response )
45+ user = event .get ('user' )
46+ user_id = f'<@{ user } >' if user else 'Hey you'
47+ await app .plugins ["slack" ].api .query (methods .CHAT_POST_MESSAGE , data = dict (
48+ channel = event ['channel' ],
49+ text = f'{ user_id } - this had better be important!'
50+ ))
4651
4752
4853async def tech_tips (event : Message , app : SirBot ):
4954 if not_bot_message (event ):
50- logger .info (
51- f'tech logging: { event } ' )
55+ logger .info (f'tech tips logging: { event } ' )
5256 try :
53- tech_terms : dict = await TechTerms (event ['channel' ], event ['user' ],
54- event .get ('text' ), app ).grab_values ()
55-
57+ tech_terms = await TechTerms (
58+ event ['channel' ], event ['user' ],
59+ event .get ('text' ), app
60+ ).grab_values ()
5661 await app .plugins ["slack" ].api .query (methods .CHAT_POST_MESSAGE , tech_terms ['message' ])
57- except Exception as E :
58- logger .exception (E )
62+
63+ except Exception :
64+ logger .debug (f'Exception thrown while logging message_changed { event } ' )
5965
6066
6167async def message_changed (event : Message , app : SirBot ):
6268 """
6369 Logs all message edits not made by a bot.
6470 """
65- # need to check for bot_delete as deletes with replies that result in a "tombstone" also send as edits
66- if not_bot_message (event ) and not_bot_delete (event ):
67- try :
71+ try :
72+ # need to check for bot_delete as deletes with replies that
73+ # result in a "tombstone" also send as edits
74+ if not_bot_message (event ) and not_bot_delete (event ):
6875 logger .info (
6976 f'CHANGE_LOGGING: edited: { event ["ts" ]} for user: { event ["previous_message" ]["user" ]} \n { event } ' )
70-
71- except Exception as E :
72- logger .exception (E )
73- logger .debug (event )
77+ except ValueError as e :
78+ logger .debug (f'Exception thrown while logging message_changed. Event: { event } || Error: { e } ' )
7479
7580
7681async def message_deleted (event : Message , app : SirBot ):
7782 """
7883 Logs all message deletions not made by a bot.
7984 """
80- if not_bot_delete (event ):
81- try :
82- logger .info (
83- f'CHANGE_LOGGING: deleted: { event ["ts" ]} \n Event: { event } ' )
84-
85- except Exception as E :
86- logger .exception (E )
87- logger .debug (event )
85+ try :
86+ if not_bot_delete (event ):
87+ logger .info (f'CHANGE_LOGGING: deleted: { event ["ts" ]} \n Event: { event } ' )
88+ except ValueError as e :
89+ logger .debug (f'Exception thrown while logging message_deleted. Event: { event } || Error: { e } ' )
0 commit comments