From d9465344017d72cf5928dae22a58a449a75fd26e Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 3 Dec 2023 14:14:11 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E5=AD=97=E5=88=97=E3=82=AB=E3=83=83?= =?UTF-8?q?=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common_module.py | 21 ++++++++++++++++++++- main.py | 20 +++++++++++++++++++- talk.py | 2 ++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/common_module.py b/common_module.py index b052dab..e50bff3 100644 --- a/common_module.py +++ b/common_module.py @@ -7,7 +7,26 @@ class CommonModule: return unicodedata.east_asian_width (c) in ['F', 'W', 'A'] @classmethod - def string_width_per_pt (cls, string: str) -> float: + def len_by_full (cls, string: str) -> float: return sum ([1 if cls.is_wide (c) else .5 for c in string.decode ('utf-8')]) + @classmethod + def index_by_f2c (cls, string: str, index: float) -> int: + i = 0 + work = '' + for c in string.decode ('utf-8'): + work += c + if cls.len_by_full (work) > index: + break + else: + i += 1 + + return i + + @classmethod + def mid_by_full (cls, string: str, start: float, length: float) -> str: + trimmed_left = string[cls.index_by_f2c (string, start):] + + return trimmed_left[:cls.index_by_f2c (trimmed_left, length)] + diff --git a/main.py b/main.py index 196b910..b966e02 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ from aques import Aques from playsound import playsound from common_module import CommonModule from youtube import * +from datetime import datetime class Main: @@ -42,7 +43,13 @@ class Main: screen.blit (balloon, (0, 0)) screen.blit ( - user_font.render ('> ' + message, True, (0, 0, 0)), + user_font.render ( + '> ' + (message + if (CommonModule.len_by_full (message) + <= 21) + else (CommonModule.mid_by_full ( + message, 0, 19.5) + + '...')), True, (0, 0, 0)), (120, 70)) screen.blit ( nizika_font.render (answer, True, (192, 0, 0)), @@ -71,6 +78,17 @@ class Main: f'live_chat.is_alive () == {live_chat.is_alive ()}', True, (0, 0, 0)), (i % 2, i // 2 * 2)) + screen.blit ( + system_font.render (datetime.now (), True, (0, 0, 0)), + (i % 2, 32 + i // 2 * 2)) + + if live_chat.is_alive (): + screen.blit ( + system_font.render ( + f'messages == {[c.message + for c in live_chat.get ().items]}', + True, (0, 0, 0)), + (i % 2, 64 + i // 2 * 2)) pygame.display.update () diff --git a/talk.py b/talk.py index c0fc951..268166d 100644 --- a/talk.py +++ b/talk.py @@ -6,6 +6,8 @@ from connection import * class Talk: + DUMMY_RESPONSE: str = 'あいうえおかきくけこさしすせそたちつてとなにぬねの' + max_tokens_count: int = 100 responses_count: int = 1 temperature: float = .7