コミットを比較
4 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| c62a37d990 | |||
| e0a51abf2e | |||
| 0316aebc94 | |||
| 5e82637845 |
@@ -45,3 +45,9 @@ class CommonModule:
|
||||
|
||||
return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|
||||
|
||||
@staticmethod
|
||||
def rad_to_deg (
|
||||
rad: float) \
|
||||
-> float:
|
||||
return rad * 180 / CMath.PI
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# vim: nosmartindent autoindent
|
||||
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -11,7 +10,6 @@ from datetime import datetime, timedelta
|
||||
import emoji
|
||||
import ephem
|
||||
import pygame
|
||||
import pygame.gfxdraw
|
||||
import pytchat
|
||||
from playsound import playsound
|
||||
from pygame.locals import *
|
||||
@@ -121,7 +119,7 @@ class Main:
|
||||
# Youtube Chat から取得したコメントたち
|
||||
chat_items: list = []
|
||||
|
||||
# 会話の履歴
|
||||
# 会話の履歴(3 件分保持)
|
||||
histories: list = []
|
||||
|
||||
while (True):
|
||||
@@ -144,32 +142,29 @@ class Main:
|
||||
# 日の入終了
|
||||
sunset_end: datetime = sunset_start + timedelta (hours = 1)
|
||||
|
||||
# 時刻つき観測地
|
||||
observer_with_time: ephem.Observer = observer
|
||||
observer_with_time.date = datetime.now () - timedelta (hours = 9)
|
||||
# 月の出開始
|
||||
'todo'
|
||||
|
||||
# 月の出終了
|
||||
'todo'
|
||||
|
||||
# 月の入開始
|
||||
'todo'
|
||||
|
||||
# 月の入終了
|
||||
'todo'
|
||||
|
||||
# 日の角度
|
||||
observer_with_time: ephem.Observer = observer
|
||||
observer_with_time.date = datetime.now () - timedelta (hours = 9)
|
||||
sun.compute (observer_with_time)
|
||||
sun_alt: float = math.degrees (sun.alt)
|
||||
sun_az: float = math.degrees (sun.az)
|
||||
|
||||
# 月の角度
|
||||
moon.compute (observer_with_time)
|
||||
moon_alt: float = math.degrees (moon.alt)
|
||||
moon_az: float = math.degrees (moon.az)
|
||||
|
||||
# 月齢
|
||||
new_moon_dt: datetime = ephem.localtime (
|
||||
ephem.previous_new_moon (observer_with_time.date))
|
||||
moon_days_old: float = (
|
||||
(datetime.now () - new_moon_dt).total_seconds ()
|
||||
/ 60 / 60 / 24)
|
||||
sun_alt: float = CommonModule.rad_to_deg (sun.alt)
|
||||
|
||||
# 背景描画
|
||||
cls.draw_bg (screen, bg_day, bg_evening, bg_night, bg_grass,
|
||||
kita, jojoko,
|
||||
sunrise_start, sunrise_end, sunset_start, sunset_end,
|
||||
sun_alt, sun_az, moon_alt, moon_az, moon_days_old)
|
||||
sun_alt)
|
||||
|
||||
# 左上に時刻表示
|
||||
for i in range (4):
|
||||
@@ -299,8 +294,7 @@ class Main:
|
||||
bg_grass, kita, jojoko,
|
||||
sunrise_start, sunrise_end,
|
||||
sunset_start, sunset_end,
|
||||
sun_alt, sun_az, moon_alt, moon_az,
|
||||
moon_days_old)
|
||||
sun_alt)
|
||||
|
||||
chat_item.author = {'name': 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ',
|
||||
'id': '',
|
||||
@@ -326,31 +320,24 @@ class Main:
|
||||
@classmethod
|
||||
def draw_bg (
|
||||
cls,
|
||||
screen: pygame.Surface,
|
||||
bg_day: pygame.Surface,
|
||||
bg_evening: pygame.Surface,
|
||||
bg_night: pygame.Surface,
|
||||
bg_grass: pygame.Surface,
|
||||
kita: pygame.Surface,
|
||||
jojoko_original: pygame.Surface,
|
||||
sunrise_start: datetime,
|
||||
sunrise_end: datetime,
|
||||
sunset_start: datetime,
|
||||
sunset_end: datetime,
|
||||
sun_alt: float,
|
||||
sun_az: float,
|
||||
moon_alt: float,
|
||||
moon_az: float,
|
||||
moon_days_old: float) \
|
||||
screen: pygame.Surface,
|
||||
bg_day: pygame.Surface,
|
||||
bg_evening: pygame.Surface,
|
||||
bg_night: pygame.Surface,
|
||||
bg_grass: pygame.Surface,
|
||||
kita: pygame.Surface,
|
||||
jojoko: pygame.Surface,
|
||||
sunrise_start: datetime,
|
||||
sunrise_end: datetime,
|
||||
sunset_start: datetime,
|
||||
sunset_end: datetime,
|
||||
sun_alt: float) \
|
||||
-> None:
|
||||
sunrise_centre: datetime = (
|
||||
sunrise_start + (sunrise_end - sunrise_start) / 2)
|
||||
sunset_centre: datetime = (
|
||||
sunset_start + (sunset_end - sunset_start) / 2)
|
||||
|
||||
jojoko: pygame.Surface = cls.get_jojoko (jojoko_original,
|
||||
moon_days_old)
|
||||
|
||||
dt: datetime = datetime.now ()
|
||||
|
||||
if sunrise_centre <= dt < sunset_centre:
|
||||
@@ -367,48 +354,15 @@ class Main:
|
||||
else:
|
||||
bg_evening.set_alpha (0)
|
||||
|
||||
if sunrise_start <= dt < sunset_end:
|
||||
jojoko.set_alpha (255 - 255 / 15 * abs (moon_days_old - 15))
|
||||
else:
|
||||
jojoko.set_alpha (255)
|
||||
|
||||
screen.blit (bg_evening, (0, 0))
|
||||
|
||||
if (moon_az < 180) and (-10 <= moon_alt < 40):
|
||||
y = ((CWindow.HEIGHT / 2 + 100)
|
||||
- (CWindow.HEIGHT / 2 + 200) / 30 * moon_alt)
|
||||
screen.blit (jojoko, jojoko.get_rect (center = (400, y)))
|
||||
|
||||
screen.blit (bg_grass, (0, 0))
|
||||
|
||||
if (sun_az < 180) and (-10 <= sun_alt < 40):
|
||||
if -10 <= sun_alt < 40:
|
||||
y = ((CWindow.HEIGHT / 2 + 100)
|
||||
- (CWindow.HEIGHT / 2 + 200) / 30 * sun_alt)
|
||||
screen.blit (kita, kita.get_rect (center = (400, y)))
|
||||
|
||||
screen.blit (bg_grass, (0, 0))
|
||||
|
||||
@staticmethod
|
||||
def get_jojoko (
|
||||
jojoko_original: pygame.Surface,
|
||||
moon_days_old: float) \
|
||||
-> pygame.Surface:
|
||||
jojoko: pygame.Surface = jojoko_original.copy ()
|
||||
|
||||
jojoko.set_colorkey ((0, 255, 0))
|
||||
|
||||
for i in range (200):
|
||||
if 1 <= moon_days_old < 15:
|
||||
pygame.gfxdraw.bezier (jojoko, ((0, 100 + i), (100, 180 * moon_days_old / 7 - 80 + i), (200, 100 + i)), 3, (0, 255, 0))
|
||||
elif moon_days_old < 16:
|
||||
pass
|
||||
elif moon_days_old < 30:
|
||||
pygame.gfxdraw.bezier (jojoko, ((0, 100 - i), (100, 180 * (moon_days_old - 15) / 7 - 80 - i), (200, 100 - i)), 3, (0, 255, 0))
|
||||
else:
|
||||
jojoko.fill ((0, 255, 0))
|
||||
|
||||
return jojoko
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Main.main (sys.argv, len (sys.argv))
|
||||
|
||||
@@ -24,13 +24,7 @@ class Talk:
|
||||
top_p: float = 1.
|
||||
|
||||
@classmethod
|
||||
def main (
|
||||
cls,
|
||||
message: str,
|
||||
name: str | None = None,
|
||||
histories: list = [],
|
||||
goatoh_mode: bool = False,
|
||||
) -> str:
|
||||
def main (cls, message: str, name: str | None = None, histories: list = [], goatoh_mode: bool = False) -> str:
|
||||
# ChatGPT API Organisation ID
|
||||
openai.organization = OPENAI_ORGANISATION
|
||||
|
||||
@@ -44,13 +38,8 @@ class Talk:
|
||||
return answer.content if answer is not None else cls.DUMMY_RESPONSE
|
||||
|
||||
@classmethod
|
||||
def __get_message (
|
||||
cls,
|
||||
message: str,
|
||||
name: str | None,
|
||||
histories: list,
|
||||
goatoh_mode: bool = False,
|
||||
) -> chat.chat_completion_message.ChatCompletionMessage | None:
|
||||
def __get_message (cls, message: str, name: str | None, histories: list, goatoh_mode: bool = False) \
|
||||
-> chat.chat_completion_message.ChatCompletionMessage | None:
|
||||
# プロンプト(JSON 等外部ファイルに置くことを検討)
|
||||
if goatoh_mode:
|
||||
messages: list = [{'role': 'system',
|
||||
@@ -214,13 +203,13 @@ class Talk:
|
||||
+ 'ふざけるのはいい加減にするぬ゛ぬ゛ん゛。'))},
|
||||
|
||||
{'role': 'system',
|
||||
'content': '洗澡歌(しーざおぐあ)歌って'},
|
||||
'content': '洗操歌(しーざおぐあ)歌って'},
|
||||
|
||||
{'role': 'assistant',
|
||||
'content': ('おけだぬ゛~゛ん゛(苦笑)。'
|
||||
+ '毛巾浴帽小鴨鴨水溫剛剛好♪'
|
||||
+ '潑潑水來搓泡泡今天眞是美妙♪'
|
||||
+ '大聲唱歌扭扭腰我愛洗洗澡♪'
|
||||
+ '毛巾浴帽小鸭鸭水温刚刚好♪'
|
||||
+ '泼泼水来搓泡泡今天真是美妙♪'
|
||||
+ '大声唱歌扭扭腰我爱洗洗澡♪'
|
||||
+ 'だぬ゛ん♪')},
|
||||
|
||||
{'role': 'system',
|
||||
|
||||
新しい課題から参照
ユーザをブロックする