benjaminvr

Python - NotificationManager

Jul 27th, 2021
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from DiscordNotifier import Notification, DiscordNotifier
  2. from db import getDiscordNotificationMetrics
  3.  
  4. class NotificationManager:
  5.     def __init__(self, execute_discord_notification=True):
  6.         self.execute_discord_notification = execute_discord_notification
  7.         self.discord_execution_info = None
  8.  
  9.     def _HandleFinish(self):
  10.         if self.discord_execution_info is not None:
  11.             print('Info: {}'.format(self.discord_execution_info))
  12.  
  13.     def Run(self):
  14.         if self.execute_discord_notification:
  15.             data = self._FetchDiscordData()
  16.  
  17.             if len(data) == 11:
  18.                 n = Notification(data[0], data[1], data[2], data[3], data[4], data[5],
  19.                                               data[6], data[7], data[8], data[9], data[10])
  20.                 n.ConstructMessage()
  21.                 d = DiscordNotifier().Notify(n.constructed_message)
  22.                 if d:
  23.                     self.discord_execution_info = "Webhook: successfully sent notification"
  24.                 else:
  25.                     self.discord_execution_info = "Webhook: Failed to send notification"
  26.             else:
  27.                 self.discord_execution_info = "Data length mismatch"
  28.  
  29.         self._HandleFinish()
  30.  
  31.     def _FetchDiscordData(self):
  32.         return getDiscordNotificationMetrics()
  33.  
  34.  
  35. if __name__ == "__main__":
  36.     NotificationManager().Run()
Advertisement
Add Comment
Please, Sign In to add comment