Move _distribute_buttons to MultiBot
This commit is contained in:
@@ -225,7 +225,7 @@ class FlanaBot(PenaltyBot, PollBot, ScraperBot, WeatherBot, MultiBot, ABC):
|
||||
await self.delete_message(message)
|
||||
await self.send(
|
||||
f'<b>Roles de {message.author.name}:</b>',
|
||||
self._distribute_buttons(options),
|
||||
self._distribute_buttons(options, vertically=True),
|
||||
message,
|
||||
buttons_key=ButtonsGroup.ROLES,
|
||||
contents={'user_id': message.author.id}
|
||||
@@ -247,7 +247,7 @@ class FlanaBot(PenaltyBot, PollBot, ScraperBot, WeatherBot, MultiBot, ABC):
|
||||
message.buttons_info.presser_user.roles.append(role)
|
||||
user_role_names.append(role.name)
|
||||
|
||||
await self.edit(self._distribute_buttons(await self._role_state_options(message, user_role_names)), message)
|
||||
await self.edit(self._distribute_buttons(await self._role_state_options(message, user_role_names), vertically=True), message)
|
||||
|
||||
message.buttons_info.presser_user.save()
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import math
|
||||
import os
|
||||
import random
|
||||
from collections import defaultdict
|
||||
from typing import Sequence
|
||||
|
||||
import discord
|
||||
import flanautils
|
||||
@@ -69,15 +68,6 @@ class FlanaDiscBot(DiscordBot, FlanaBot):
|
||||
group_id = self.get_group_id(group_)
|
||||
return [role for role in await self.get_group_roles(group_) if role.id in CHANGEABLE_ROLES[group_id]]
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
def _distribute_buttons(self, texts: Sequence[str]) -> list[list[str]]:
|
||||
texts = [f'{text[:multibot_constants.DISCORD_BUTTON_MAX_CHARACTERS - 3]}...' if len(text) > multibot_constants.DISCORD_BUTTON_MAX_CHARACTERS else text for text in texts]
|
||||
|
||||
if len(texts) <= multibot_constants.DISCORD_BUTTONS_MAX:
|
||||
return flanautils.chunks(texts, 1)
|
||||
else:
|
||||
return flanautils.chunks(texts, multibot_constants.DISCORD_BUTTONS_MAX)
|
||||
|
||||
async def _heat_channel(self, channel: discord.VoiceChannel):
|
||||
async def set_fire_to(channel_key: str, depends_on: str, firewall=0):
|
||||
fire_score = random.randint(0, channels[depends_on]['n_fires'] - channels[channel_key]['n_fires']) - firewall // 2
|
||||
|
||||
@@ -4,9 +4,8 @@ __all__ = ['whitelisted_event', 'FlanaTeleBot']
|
||||
|
||||
import functools
|
||||
import os
|
||||
from typing import Callable, Sequence
|
||||
from typing import Callable
|
||||
|
||||
import flanautils
|
||||
import telethon.tl.functions
|
||||
from flanautils import Media, OrderedSet
|
||||
from multibot import TelegramBot, find_message, user_client
|
||||
@@ -48,10 +47,6 @@ class FlanaTeleBot(TelegramBot, FlanaBot):
|
||||
# ----------------------------------------------------------- #
|
||||
# -------------------- PROTECTED METHODS -------------------- #
|
||||
# ----------------------------------------------------------- #
|
||||
def _distribute_buttons(self, texts: Sequence[str]) -> list[list[str]]:
|
||||
# noinspection PyTypeChecker
|
||||
return flanautils.chunks(texts, 1)
|
||||
|
||||
@user_client
|
||||
async def _get_contacts_ids(self) -> list[int]:
|
||||
async with self.user_client:
|
||||
|
||||
@@ -92,7 +92,7 @@ class PollBot(MultiBot, ABC):
|
||||
else:
|
||||
buttons = list(message.contents['poll']['votes'].keys())
|
||||
|
||||
await self.edit(self._distribute_buttons(buttons), message)
|
||||
await self.edit(self._distribute_buttons(buttons, vertically=True), message)
|
||||
|
||||
# ---------------------------------------------- #
|
||||
# HANDLERS #
|
||||
@@ -163,7 +163,7 @@ class PollBot(MultiBot, ABC):
|
||||
if final_options := [f'{option[0].upper()}{option[1:]}' for option in self._get_options(message.text, discarded_words)]:
|
||||
await self.send(
|
||||
f"Encuesta {'multirespuesta ' if is_multiple_answer else ''}en curso...",
|
||||
self._distribute_buttons(final_options),
|
||||
self._distribute_buttons(final_options, vertically=True),
|
||||
message,
|
||||
buttons_key=ButtonsGroup.POLL,
|
||||
contents={'poll': {
|
||||
|
||||
Reference in New Issue
Block a user