Example #1
0
 def update_groups(task_self, pk):
     user = User.objects.get(pk=pk)
     logger.debug("Updating discord groups for user %s" % user)
     if DiscordTasks.has_account(user):
         groups = []
         for group in user.groups.all():
             groups.append(str(group.name))
         if len(groups) == 0:
             logger.debug("No syncgroups found for user. Adding empty group.")
             groups.append('empty')
         logger.debug("Updating user %s discord groups to %s" % (user, groups))
         try:
             DiscordOAuthManager.update_groups(user.discord.uid, groups)
         except DiscordApiBackoff as bo:
             logger.info("Discord group sync API back off for %s, "
                         "retrying in %s seconds" % (user, bo.retry_after))
             raise task_self.retry(countdown=bo.retry_after)
         except Exception as e:
             if task_self:
                 logger.exception("Discord group sync failed for %s, retrying in 10 mins" % user)
                 raise task_self.retry(countdown=60 * 10)
             else:
                 # Rethrow
                 raise e
         logger.debug("Updated user %s discord groups." % user)
     else:
         logger.debug("User does not have a discord account, skipping")
Example #2
0
 def update_groups(task_self, pk):
     user = User.objects.get(pk=pk)
     logger.debug("Updating discord groups for user %s" % user)
     if DiscordTasks.has_account(user):
         groups = []
         for group in user.groups.all():
             groups.append(str(group.name))
         if len(groups) == 0:
             logger.debug("No syncgroups found for user. Adding empty group.")
             groups.append('empty')
         logger.debug("Updating user %s discord groups to %s" % (user, groups))
         try:
             DiscordOAuthManager.update_groups(user.discord.uid, groups)
         except DiscordApiBackoff as bo:
             logger.info("Discord group sync API back off for %s, "
                         "retrying in %s seconds" % (user, bo.retry_after_seconds))
             raise task_self.retry(countdown=bo.retry_after_seconds)
         except Exception as e:
             if task_self:
                 logger.exception("Discord group sync failed for %s, retrying in 10 mins" % user)
                 raise task_self.retry(countdown=60 * 10)
             else:
                 # Rethrow
                 raise e
         logger.debug("Updated user %s discord groups." % user)
     else:
         logger.debug("User does not have a discord account, skipping")
Example #3
0
 def delete_user(cls, user, notify_user=False):
     if cls.has_account(user):
         logger.debug("User %s has discord account %s. Deleting." % (user, user.discord.uid))
         if DiscordOAuthManager.delete_user(user.discord.uid):
             user.discord.delete()
             if notify_user:
                 notify(user, 'Discord Account Disabled', level='danger')
             return True
     return False
Example #4
0
 def update_nickname(self, pk):
     user = User.objects.get(pk=pk)
     logger.debug("Updating discord nickname for user %s" % user)
     if DiscordTasks.has_account(user):
         character = EveManager.get_main_character(user)
         logger.debug("Updating user %s discord nickname to %s" % (user, character.character_name))
         try:
             DiscordOAuthManager.update_nickname(user.discord.uid, character.character_name)
         except Exception as e:
             if self:
                 logger.exception("Discord nickname sync failed for %s, retrying in 10 mins" % user)
                 raise self.retry(countdown=60 * 10)
             else:
                 # Rethrow
                 raise e
         logger.debug("Updated user %s discord nickname." % user)
     else:
         logger.debug("User %s does not have a discord account" % user)
Example #5
0
 def update_nickname(self, pk):
     user = User.objects.get(pk=pk)
     logger.debug("Updating discord nickname for user %s" % user)
     if DiscordTasks.has_account(user):
         character = EveManager.get_main_character(user)
         logger.debug("Updating user %s discord nickname to %s" % (user, character.character_name))
         try:
             DiscordOAuthManager.update_nickname(user.discord.uid, character.character_name)
         except Exception as e:
             if self:
                 logger.exception("Discord nickname sync failed for %s, retrying in 10 mins" % user)
                 raise self.retry(countdown=60 * 10)
             else:
                 # Rethrow
                 raise e
         logger.debug("Updated user %s discord nickname." % user)
     else:
         logger.debug("User %s does not have a discord account" % user)
Example #6
0
 def delete_user(cls, user, notify_user=False):
     if cls.has_account(user):
         logger.debug("User %s has discord account %s. Deleting." % (user, user.discord.uid))
         if DiscordOAuthManager.delete_user(user.discord.uid):
             user.discord.delete()
             if notify_user:
                 notify(user, 'Discord Account Disabled', level='danger')
             return True
     return False
Example #7
0
 def add_user(cls, user, code):
     user_id = DiscordOAuthManager.add_user(code)
     if user_id:
         discord_user = DiscordUser()
         discord_user.user = user
         discord_user.uid = user_id
         discord_user.save()
         if settings.DISCORD_SYNC_NAMES:
             cls.update_nickname.delay(user.pk)
         cls.update_groups.delay(user.pk)
         return True
     return False
Example #8
0
 def add_user(cls, user, code):
     user_id = DiscordOAuthManager.add_user(code)
     if user_id:
         discord_user = DiscordUser()
         discord_user.user = user
         discord_user.uid = user_id
         discord_user.save()
         if settings.DISCORD_SYNC_NAMES:
             cls.update_nickname.delay(user.pk)
         cls.update_groups.delay(user.pk)
         return True
     return False