Browse Source

文字列カット追加

btc-sounds
みてるぞ 1 year ago
parent
commit
d946534401
3 changed files with 41 additions and 2 deletions
  1. +20
    -1
      common_module.py
  2. +19
    -1
      main.py
  3. +2
    -0
      talk.py

+ 20
- 1
common_module.py View File

@@ -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)]


+ 19
- 1
main.py View File

@@ -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 ()



+ 2
- 0
talk.py View File

@@ -6,6 +6,8 @@ from connection import *


class Talk:
DUMMY_RESPONSE: str = 'あいうえおかきくけこさしすせそたちつてとなにぬねの'

max_tokens_count: int = 100
responses_count: int = 1
temperature: float = .7


Loading…
Cancel
Save