def kickMembersFromGroup(thread): d = date.today() if thread.generationTime > thread.logTime: d = d - timedelta(days=1) shouldKick = ReportMaker(d, thread.id).membersToBeKicked telegramAgents = [] groups = Group.objects.filter(thread_id=thread.id, statusUpdateEnabled=True) for group in groups: obj = [group.telegramBot, group.telegramGroup] if obj not in telegramAgents: telegramAgents.append(obj) for agent in telegramAgents: bot = telegram.Bot(token=agent[0]) for user in shouldKick: exceptions = StatusException.objects.filter(isPaused=True) for exception in exceptions: if exception.user != user: profile = Profile.objects.get(user=user) bot.kick_chat_member(chat_id=agent[1], user_id=profile.telegram_id) bot.unban_chat_member( chat_id=agent[1], user_id=profile.telegram_id )
def sendDiscordReport(thread): d = date.today() if thread.generationTime > thread.logTime: d = d - timedelta(days=1) logs = ReportMaker(d, thread.id, isTelegram=False).message discordAgents = [] groups = Group.objects.filter(thread_id=thread.id, statusUpdateEnabled=True) for group in groups: obj = [group.discordBot, group.discordGroup, group.discordChannel] if obj not in discordAgents: discordAgents.append(obj) for agent in discordAgents: discord_client = Discord(obj=agent, message=logs) discord_client.sendMessage()
def kickMembersFromGroup(thread, telegram_kick=False, discord_kick=False): d = date.today() if thread.generationTime > thread.logTime: d = d - timedelta(days=1) shouldKick = ReportMaker(d, thread.id, isTelegram=True).membersToBeKicked telegramAgents = [] discordAgents = [] groups = Group.objects.filter(thread_id=thread.id, statusUpdateEnabled=True) for group in groups: discord_obj = [ group.discordBot, group.discordGroup, group.discordChannel, group.discordMemberRole ] obj = [group.telegramBot, group.telegramGroup] if obj not in telegramAgents: telegramAgents.append(obj) if discord_obj not in discordAgents: discordAgents.append(discord_obj) if telegram_kick: for agent in telegramAgents: bot = telegram.Bot(token=agent[0]) for user in shouldKick: profile = Profile.objects.get(user=user) try: bot.kick_chat_member(chat_id=agent[1], user_id=profile.telegram_id) bot.unban_chat_member(chat_id=agent[1], user_id=profile.telegram_id) except: pass if discord_kick: for discordAgent in discordAgents: for user in shouldKick: profile = Profile.objects.get(user=user) try: discord_client = Discord(obj=discord_obj, userID=profile.discord_id) discord_client.removeMemberRole() except: pass
def sendTelegramReport(thread): d = date.today() if thread.generationTime > thread.logTime: d = d - timedelta(days=1) logs = ReportMaker(d, thread.id, isTelegram=True).message telegramAgents = [] groups = Group.objects.filter(thread_id=thread.id, statusUpdateEnabled=True) for group in groups: obj = [group.telegramBot, group.telegramGroup] if obj not in telegramAgents: telegramAgents.append(obj) for agent in telegramAgents: bot = telegram.Bot(token=agent[0]) bot.send_message(chat_id=agent[1], text=logs, parse_mode=telegram.ParseMode.HTML)