Example #1
0
 async def uwarn(self, ctx, user_id=None, *, reason=None):
     if user_id is not None:
         if user_id not in ['all', 'wszyscy']:
             if reason is not None:
                 if len(reason) <= 30:
                     user_id = check_mention(user_id)
                     if user_id:
                         user = self.bot.get_user(user_id)
                         if user is not None:
                             update_warn(user_id, reason)
                             await ctx.send(embed=success_em(
                                 f'Opis ostrzeżenia dla **{user.name}** został zaktualizowany.'
                                 f'```{reason}```'))
                         else:
                             await ctx.send(embed=error_em(
                                 'Nie mogę znaleźć takiego użytkownika.'))
                     else:
                         await ctx.send(
                             embed=error_em('Błędny format komendy.'))
                 else:
                     await ctx.send(embed=error_em(
                         'Maksymalna długość powodu ostrzeżenia to **30 znaków**.'
                     ))
             else:
                 await ctx.send(embed=error_em('Nie podałeś(aś) powodu.'))
         else:
             count = 0
             msg = await ctx.send(embed=please_wait_em())
             for record in get_warns():
                 member = ctx.guild.get_member(record[0])
                 if member is not None:
                     count += 1
                     for role in range(3):
                         try:
                             warn_role = ctx.guild.get_role(
                                 warn_roles_ids()[role + 1])
                             if role < record[1]:
                                 await member.add_roles(
                                     warn_role,
                                     reason=
                                     f'Użytkownik posiada {record[1]} poziom ostrzeżeń.'
                                 )
                             else:
                                 await member.remove_roles(
                                     warn_role,
                                     reason=
                                     f'Użytkownik posiada {record[1]} poziom ostrzeżeń.'
                                 )
                         except Forbidden:
                             await msg.edit(embed=error_em(
                                 'Nie mam uprawnień do zmiany ról!'))
                         finally:
                             print(member.display_name)
             await msg.edit(embed=success_em(
                 f'Zaktualizowani użytkownicy: **{count}**'))
     else:
         await ctx.send(embed=error_em('Nie podałeś(aś) użytkownika.'))
Example #2
0
 async def wiat_for_reaction_response(self, reaction: Reaction, user: User):
     if user == self.starter and reaction.count > 1 and reaction.message.id == self.msg.id:
         if reaction.emoji == self.emoji_up:
             await self._rm_reaction_listener()
             await self.msg.edit(embed=success_em(
                 'Wiadomość zatwierdzona.'
             ))
             await self._event_confirm(reaction.message.guild)
         elif reaction.emoji == self.emoji_down:
             await self._rm_reaction_listener()
             await self.msg.edit(embed=success_em(
                 'Wysyłanie wiadomości zostało anulowane.'
             ))
Example #3
0
 async def warn(self, ctx, user_id=None, *, reason='Brak'):
     if user_id:
         user_id = check_mention(user_id)
         if user_id:
             user = self.bot.get_user(user_id)
             if user:
                 warns = get_warn(user_id)
                 if len(warns) > 0:
                     count = warns[0][1] + 1
                 else:
                     count = 1
                 add_warn(user_id, reason)
                 if count <= 3:
                     member = ctx.guild.get_member(user_id)
                     try:
                         await member.add_roles(
                             ctx.guild.get_role(warn_roles_ids()[count]))
                     except AttributeError:
                         pass
                     await ctx.send(embed=success_em(
                         f'Ostrzeżono: **{user.name}**.\n'
                         f'Powód: **{reason if reason else "Brak"}**.\n'
                         f'To jest **{count}** ostrzeżenie.'))
                     try:
                         await user.send(embed=error_em(
                             f' Powód:```\n{reason if reason else "Brak"}```To Twoje **{count}** ostrzeżenie.',
                             ':exclamation: Zostałeś ostrzeżony(a)!'))
                     except Forbidden:
                         await ctx.send(embed=error_em(
                             f'Użytkownik **{user}** zablokował mnie (warto to zapisać).',
                             ':no_entry: Ojć!'))
                     except HTTPException:
                         await ctx.send(embed=error_em(
                             f'Nie mogę wysłać do **{user}** wiadomości przez problem z Discordem.'
                         ))
                 else:
                     await ctx.guild.ban(user=user,
                                         reason='Przekroczenie 3 ostrzeżeń',
                                         delete_message_days=3)
                     await ctx.send(embed=error_em(
                         f'Użytkownik {user.name} został zbanowany.',
                         title=':no_entry: Koniec ostrzeżeń'))
                     del_warns(user_id)
             else:
                 await ctx.send(
                     embed=error_em('Nie znaleziono użytkownika.'))
         else:
             await ctx.send(embed=error_em('Błędny format komendy.'))
     else:
         await ctx.send(
             embed=error_em('Musisz podać, kogo chcesz upomnieć.'))
Example #4
0
    async def punkty(self, ctx, user=None, option=None, amount=None):
        if not user:
            await ctx.send(embed=error_em('Nie podałeś użytkownika.'))

        elif not option:
            await ctx.send(embed=error_em('Nie podałeś opcji.'))

        elif option not in ['+', '-', '=']:
            await ctx.send(embed=error_em('Błędna opcja.'))

        elif not amount:
            await ctx.send(embed=error_em('Nie podałeś wartości punktów.'))

        elif amount == 0:
            await ctx.send(embed=error_em('Musisz podać liczbę różną od zera.')
                           )

        else:
            try:
                amount = int(amount)
            except ValueError:
                await ctx.send(embed=error_em('Błędna wartość.'))
            else:
                user_id = check_mention(user)
                if not user_id:
                    await ctx.send(embed=error_em('Błędnie podany użytkownik.')
                                   )
                else:
                    member = ctx.guild.get_member(user_id)
                    if not member:
                        await ctx.send(embed=error_em(
                            'Ten użytkownik nie znajduje się na tym serwerze.')
                                       )
                    else:
                        func = add_points if option == '+' else remove_points if option == '-' else set_points
                        func(user_id, amount)
                        option_human = "Dodano" if option == "+" else "Odjęto" if option == "-" else "Ustawiono"
                        await ctx.send(embed=success_em(
                            f'Punkty użytkownika **{member.display_name}** zostały zaktualizowane.\n'
                            f'**{option_human}** punkty w ilości: **{amount}**.'
                        ))
Example #5
0
 async def dwarn(self, ctx, user_id=None):
     if user_id is not None:
         user_id = check_mention(user_id)
         if user_id:
             del_warns(user_id)
             user = self.bot.get_user(user_id)
             member = ctx.guild.get_member(user_id)
             if member:
                 for i in range(3):
                     try:
                         await member.remove_roles(
                             ctx.guild.get_role(warn_roles_ids()[i + 1]))
                     except AttributeError:
                         pass
             await ctx.send(embed=success_em(
                 f'Usunięto ostrzeżenia użytkownikowi **{user.mention if user else f"`{user_id}`"}**.'
             ))
         else:
             await ctx.send(embed=error_em('Błędny format komendy.'))
     else:
         await ctx.send(embed=error_em('Nie podałeś(aś) użytkownika.'))
Example #6
0
    async def purge(self, ctx, option='start'):
        option = option.lower()
        if option in ['start', 'status', 'update', 'stop']:
            gid = ctx.guild.id
            self.settings = purge_settings(gid)
            active_role = ctx.guild.get_role(self.settings['active_role_id'])
            inactive_role = ctx.guild.get_role(self.settings['inactive_role_id'])
            purge_on = purge_enabled(gid)

            if option == 'start':
                if not purge_on:
                    await ctx.guild.get_channel(self.settings['check_channel_id']).send(
                        embed=info_em('Rozpoczęcie czystki. Proszę napisz dowolną wiadomość na tym kanale.')
                    )
                    purge_enable(gid)
                    self.bot.add_listener(self.purge_listener, 'on_message')
                    await ctx.send(embed=success_em(
                        f'Czystka włączona na kanale'
                        f' {ctx.guild.get_channel(self.settings["check_channel_id"]).mention}.'
                    ))
                else:
                    await ctx.send(embed=error_em('Czystka jest już włączona lub błąd ustawień.'))

            elif option == 'status':
                if purge_on:
                    active = 0
                    inactive = 0
                    for member in ctx.guild.members:
                        if not member.bot:
                            if active_role in member.roles:
                                active += 1
                            elif inactive_role in member.roles:
                                inactive += 1
                    await ctx.send(embed=info_em(
                        f'Aktywni: **{active}**\n'
                        f'Nieaktywni: **{inactive}**'
                    ))
                else:
                    await ctx.send(embed=error_em('Czystka nie jest włączona lub błąd ustawień.'))

            elif option == 'update':
                if purge_on:
                    msg = await ctx.send(embed=please_wait_em())
                    inactive = 0
                    for index, member in enumerate(ctx.guild.members):
                        if not member.bot:
                            if active_role not in member.roles:
                                await member.add_roles(inactive_role, reason='Czystka')
                                inactive += 1
                                print(f'[PURGE] Inactive: {member}')
                        if index % 10 == 0:
                            await msg.edit(embed=please_wait_em(
                                f'({inactive})'
                                f'**{len(ctx.guild.members) // index}%**'
                            ))
                    await msg.edit(embed=success_em(f'Dodane role `@nieaktywny`: **{inactive}**.'))
                else:
                    await ctx.send(embed=error_em('Czystka nie jest włączona lub błąd ustawień.'))

            elif option == 'stop':
                if purge_enabled(gid):
                    msg = await ctx.send(embed=please_wait_em())
                    kicked = 0
                    unable = 0
                    for member in ctx.guild.members:
                        if inactive_role in member.roles:
                            try:
                                await member.kick(reason='Czystka')
                            except Forbidden or HTTPException:
                                unable += 1
                            else:
                                kicked += 1
                    await msg.edit(embed=success_em(
                        f'Wyrzucono: **{kicked}**\n'
                        f'Niepowodzenia: **{unable}**\n'
                        f'Czystkę rozpoczęto: **{self.settings["purge_started_date"]}**'
                    ))
                    purge_disable(gid)
                    self.bot.remove_listener(self.purge_listener, 'on_message')
                else:
                    await ctx.send(embed=error_em('Czystka jest wyłączona lub błąd ustawień.'))

        else:
            await ctx.send(embed=error_em('Błędny argument'))