From b9b06596b6378a407133ca525eba3c1b8ce8d186 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Mon, 26 Sep 2022 16:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=AE=8C=E6=88=90=20messiva?= =?UTF-8?q?=20=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0=EF=BC=8C=E5=AE=8C?= =?UTF-8?q?=E6=88=90=20ServerMain(start.py)=20=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 附带添加 define 声明 - 由于系统差异未能实现编译时间戳与可执行件 md5 校验值的功能 - 附带添加 MornyHello 重写 --- define.py | 6 ++ logger/log_appender.py | 3 + logger/logger.py | 10 ++++ morny/morny_hello.py | 59 ++++++++++++++++++ start.py | 132 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 define.py create mode 100644 morny/morny_hello.py diff --git a/define.py b/define.py new file mode 100644 index 0000000..ded7e31 --- /dev/null +++ b/define.py @@ -0,0 +1,6 @@ +class Coeur_Def : + + VERSION = "0.7.2.1-py0.1" + CODE = "fuzhou" + TIMETAG = "2209261500" + \ No newline at end of file diff --git a/logger/log_appender.py b/logger/log_appender.py index a5a0da4..d387a15 100644 --- a/logger/log_appender.py +++ b/logger/log_appender.py @@ -2,6 +2,9 @@ from datetime import datetime import threading from .log import * +def output (message:Log) : + print(format_message(message)) + def format_message (log:Log) -> str : origins = log.message.split("\n") diff --git a/logger/logger.py b/logger/logger.py index e69de29..4da0fc1 100644 --- a/logger/logger.py +++ b/logger/logger.py @@ -0,0 +1,10 @@ +from logger.log import Log, LogLevels +from logger.log_appender import output + + +def trace (msg:str) : output(Log(msg, LogLevels.trace)) +def debug (msg:str) : output(Log(msg, LogLevels.debug)) +def info (msg:str) : output(Log(msg, LogLevels.info)) +def warn(msg:str) : output(Log(msg, LogLevels.warn)) +def error (msg:str) : output(Log(msg, LogLevels.error)) +def fatal (msg:str) : output(Log(msg, LogLevels.fatal)) diff --git a/morny/morny_hello.py b/morny/morny_hello.py new file mode 100644 index 0000000..de6afa0 --- /dev/null +++ b/morny/morny_hello.py @@ -0,0 +1,59 @@ + +def morny_hello_text () -> str: + + return r"""ttt///t/////fucj(\tvnxtf{< .' .. .:i` . . ^!`l|-^i+,!_[:1/|{i?//\//jf\\\///\\\\//\\\//////\\/\\\\\\\\\\\\\\//\\\\/\\\\/\\//\\\///\\\\\\\\\\\\\\\\\\\\fnncvvU0O00QCx!!". .. ` + tt//////////\jzjrucnjt/?{j,,"' . .' .. .":. .;{: ' "`.,1(<."i?)\(-}\\\(((\\/\\\\\\\\\\\\\\\\///\//////\\\\\\\\\\\\\\\\\\\\\\\|\\\\\\///\\///\\\\\\\\|\\\\\\|\\\\\\\\tvXvuXcxn/[Il)({_:.. ."` ., + //////////////////\////|)/([}-_<+[]>.^^""[<'`^` .''""`'.`'`"i! ^!>l:' :<" !!.IiI`+l^^`i>_<`??)1;^{\\\\\{|({({|/\]I)\\()\(]}|\\||\|||\/\\\\\\|||\\\\\\\\//\\\\/\\\\||\\\\\\\\//\\\\\\\\\\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//\\\\\\\\\\\\////\\\\\\\\\//|{{?{|)[[-; + ttt/tt//////////////////{)(\t(/tt/1~I}{-1\_^])1_+[{|(?"<1~>>+!+[}11)}[(1}]};^1\|~_1}{I:-1(I+)(|))|\\/////////\\////\\\/////\\\\\\\\\\\\\\/\//\\///\//||\////|)(//\\///){\/\(11|///({)//({[1\\\\\\\\\\|\/\\\/\//////////\\\\\\\\\//\\\\\///////\|\\\\//////\\///\ + tttt/////////////\///////\||///////t//|(|)|}|\/(\\(//(l_{{. ... ">+<^'I!: ^<(\\1}1//\\\//////////\\///\/\///\\\\\\//\\//\\\\\\\\\\\\\\///\(/\{ + t////////////////////////////////////////////////////////\/\\///////\\\\\\\\\\\\\\\/\\\\\\||\|\\\\\|\\\\/\\|\\\\\\////((|///}!:,":,^`. .;' ' '^..':. ^!;. .^^ '^^`. '' ...I[{!>:^;_i:'~\ttt/////tt//\\////////////\\\\/\\\\\\/\\\\/\\\\\)}-+[+I??i + ttt////////////////////////////////////////////////////////\\//\//\\/\\\\\\\\\\//\\\\\\||\\\/\//\\\\\\\\\/\|\\\////\1;``^;<>+!">__+I `' .. "'. .;" ;;. .:^ ``,,;'` .;]I ,-_-|\////t////t///////\/\\\\//\\\\\\//\\\///////-II1ttt///tttt/////////\/\/////\\\\////t|+<}?!-]l<{[[1-+] + t//////////////////////////////////////\/////////\////////////////\//////\//tttttttttt//////////////////////////)_)t)|}1f/{<.^,^:~: . .. '''^:-|/> '-/}-_?\/)-{?(//\(\tt////\///\\\\\\\///t1.;); .l~` '" + ///////////////////////////////////////////tt/t(|tt//]+{t\{][|////\//////////ttttt///t//t/////////////\//////|//{[|f}!l>~++~<<\//]l~?])tt//\\\\\/\\///\\|?<_}["^!;I^;]:. . + ////////////////////////////////tttt/|{[1)]~!!+>!<_(/|[-<"i!l,]tt//ttt/t////ttt//t///ttttttt////////t//t//ttt){+. :?^ '. l_-!+l;;;|!!>~~il!lllllllllll!!lI:`'. .' :I;]_}>,?tf:.+fft)l+1//\~`'I-(//\/t/|/(-1[)/?>>II:' '.`';-'` + /////////////////////////t//()\1_<>il^'''' ,!>;.,.'{tti `~tf(`'-(|fffftttttttttt/tttttttttttt///tttft//(t|]?-+!^ ."`. `. ;!I,. .?{il-\_!~<>>!lII;IllIIIIIllllllllllI;;:,:,' '"^`(f{+{>' .<{t(I!}/||t> ^(//}>;:1\]: "[:"` ^<: . II.'.. + ///////////////ttt//tt((-!+}"'^. I, ,?<:' ,:;!>~',!_~{}-1]`^!}_+\ttttttt/tttttttfff/tt\(||]-?+;,:"l" '..'.. ?]l:" -(lI;,~?~!IIIlllI:IIlI;IIIIlllllllIIIIIllII!; . . '^^;~), "~!}\/t//\\/_. '". '_i !i''' + tt//t///ttt///(]<>l>][l"'.`,. ^.^. ii ;; ~>>>. .i~I'^^<}), .;|tfftttttttttttf\]}t-!,,I` .^ '. !: . .",I;. ^,I<)/-l:;llllllI;lIll;;IIIIlllIllIlIIlIllI;><. ' .;}". '.:+](ft\}(t/t{;<\{l^>}!^l\/{>1/t(lI:I!+<<". ':" + t//tttt|?+!I!:' '` .`. ...... `^ "<^.;`^"'`,!".,^^^.,?)!. [f/+>(/tttft\tff|+^,!' '^: >[,++:`' .I^ . _?!:^. ;~{/?//)! __::. ':. '. + t/\}[{]",il'`!-<-]:`'^` .. '' .^+:'. .^'"i:`^. ';`:<_|>'.?/t/!"<)ffftf)]]!'II.,l ^' ''. '";" .' `Il, ;]>]j_;lI;ll;!!llIII>~IIIIII;: ;,~.',.<:`, 'I_|\; .i|/]^ ?(}\/////\i' '' ....'^ + tf1<}i `^. `I` .I?"'. . . ^' .^' .'` .". >}_.I|t{_(tf({~,~(); ')t};.><,. .. . .. . . .]}^{j1IlllIlI!1IlllII?{IIIIIlI;[1!I;IIllIIlIIllI<]_;+/t\(|\/1,' "` ... + )+::((:^' ll .,` . . ..'. ' :+'`{tj{,l: ^;"..;!"^.I?' '~; .` .'. . `1+ [x?-:lIlll!]r-IllI~~{~I>lllll[i\--+;;I~IIIII!l;x] "I"-<<_> >i.' l{}:itf/}[/\)(\}))|(:^^..'. `". + >.._f|i.:l,;^^''__. .^' `' "+,`]1i`!1_. ^l: .". .` '1I +JIt!IIlll;]\) >1}c(_i(!IllI_l;(f. ,_";~~+^ .. .;-i '+([i+: !//1](||/\(?:^..^^ + i'"}_,.` ''^... '. `. ^<`_> .. +x??_~]:[|!,.ll` . {+ ;Y[^|,>~IlIIf\ {/;I!\ [[-'<+l-{ _??]f\n]lllI[!;1v` `+"]-}]~" ..'`l, ''i-` l+?\\\/t{!)t[:' .^^ + ;,:: :,^..;:. . i+..;^ `_ ]]<-?l``-]' I>]?+. ^-|\\_I?]{t/?` .... + ^(\]I^~?;."!" . .. . ^<^ :( >t) _[il>|+:(U<1nYQ0Xx\> . .~xcXXYzx(n?IllI}">xCI .:1]_-" . .^. `}>!}((1-^,+?" .. + 1+,~I.(l' . ... ~|r:;`.+I?\};+t) "".-?;lI>(;]xn. '_>]!+. '^'`l:11l[|((+?: . + [-`.':;..""' lv|. .:_(;I!u> ^,",^. .;?I]?IlI}n[^ ')(I' `tlII>x1" <}1{)l "~+ |[II;\[:~zl .i;. .... `"i\\}]..!' ^.... + -" ` ' . ":` .|+<<;!\U)>^ '^`' ^"I?)c-;j/ <1I~;` .!}\(: .;"`' + ' 'l, .' ~[><+;!f()nn|]!:' ..^:!+1fcjx}}v!_)})>|n` ~^ ^;"'` .<+I<)/||\i'"<"'^ `. + II ^}_'+_!fI?_/-jJjUr\\ucJJz\|J>}?-j{]^ni" .;](),.;-<`' .^ .^' + +[" +]{.`i;I; ::."!??l.^Ywj}<, (n, ,~_:` .,, ` `` ' '... ^+-l,]}]}\j/!. . ` 'I<~`'{tl..^` + '' .,<{[>" i/i" `-[; ,<_[>^i_l,:^_! ',+l.. ^,:,,. ;~>l;^ l> ',;I^???~,'l".. .. + ;{?l. !+ .. .<1i '^' "}|{:-+-;?\[)-] ^:l1-:. '' '`, . ';.`~^ '. ..^`. + 'i+;]}!,. <))\!<|ji >((_}}?t)}\\v|]?jI!), "lf!l. ... .^ . ". + .+{>` l/z\!,>""I+~_){]vQjut_~~>>>_-<]<-)f":l_v){\/1}}}{t/\0?z~. ^' `-l . . .. . + l\ :_>>i:^+\)_-]!:>-+l'...`^;1!^ 'l>})l\n\Qt?]?]})1{][[(XC>^ ... + ^-+^.i-((?!"`:>l<[~<]nQY+?????][{\cmO||l . ''.. + '|: '^[{~)\_+++))1{uxnvt(t){{[[u0\1|({1()){-?|xfc: .. + .<-, ]-]]]})11)){{{{}{{)|{}}{1{111{11{{}}]_!"x\]Xf + ,]<\}][[[[[[[[[[[[[[[]][[[[[[[[][[[[[[]?-+!YC{z} .` + "_[}?]][[[[[[[[[[[[[[[[[[][[[[[[[[[[[[[[[]vn\?. ^ + ^. ;{_(_??][[[[[[[[[[[[[[[[[|[[[[[[[[[[[[[[[[v_(]^ + .' '. :t>/?[[[[[[[[[[[[[[[[[[[]t\][[[[[[[[[[][]?u;()_ .. .'. . . + `. .` :)!j_]][[[]]]]][[[[[[[[[[}j(/{[[[[[][[}1{~n!)ft . .. .. . .. . + ". ..' .` . "' .^":;~ti{\1]][]]]??]]]]][]]??[){[}[[[[?+}]!^':``^``,`;I.!<>?>:??i:;-;,<_..^,Ii: 'l,i+```' ..'!; ''. ?~.'<+ .li!:,1?}[[[[[[[[[[[[[[[[[[[[)1}]t[:, "O" . .' . ^!' . ". i+' . + ^. . .':`'`~/1,-<-~^'^'^^,`.."i_>^. `1t]!,^I]l^;`,I::_?]?[!:;`.`"'`l!l<1f{~>;]\1(]I>~l!l[<,,;`lI,~},^>!>l'...'": 'x' ]l>i .:I1[~]]]]}}}}}[[}}[}}}}}[[]]]??1}}[}~;:>vx. :;..:??,.' ^` I;>.";:"^' .. ^'.^"" ' .!},' . + ~!;:!".":i"^_/|]^li(\1;;it{' .[\fft+<}(/{}/)|f||'.^{/[)?!:(?+-,I+fjtil"'"+fj{i:',!!;!!^:.`r. r; !l'"i1?!i>~+_?][[[?-???]][[]?-+-]??+~<_{[_l?> ''^l;l`-}<`^.i>+l ``;I":+?!~-l ,>>l.'.;. ':!!(/!":,I + /t1ffft+{jff/ttff)];)?1(/tt\/t/tfttttfftf/1\|t\|/?<_]_]{<_]/f({fffjttf/[i>1//|tft|" :<~:+}, ]>if" .:-~ >) ^`^l)f(_{/\}-+1\()t-{j/]!:^'l<]\)+ ."_?I_{ + ffft)|)(t[_-{tjjrjrj/{(||}(rjj\1)I<\((ffj/rjffttjffftrjfffrtfff/f[1jjffffftt//)}tttff/ttt[<{rj}tf1?<:~{/j)>)fttf|?)tfffftt1_;+tf1-1|~i1, >;:} '1_ ;( .. .. `:"_1{}tjtvj)vjr/|jfff/<(tf)+1/)1j)~~-[j[l|[(/\j{:-]]([}\t""" + \ No newline at end of file diff --git a/start.py b/start.py index e69de29..bcaa662 100644 --- a/start.py +++ b/start.py @@ -0,0 +1,132 @@ +import os +import sys +import threading +from define import Coeur_Def +from logger.logger import * +from morny.morny_hello import morny_hello_text + + +thread_morny_init = "morny-init" +prop_name_token_tg_key = "TELEGRAM_BOT_API_TOKEN" +prop_name_token_morny_key = "MORNY_TG_TOKEN" + +## +## +## 启动参数的声明 + +versionEchoMode:bool = False +welcomeEchoMode:bool = False +showWelcome:bool = True +key:str = None +username:str = None; +outdatedBlock:bool = False +master:int = 793274677 +trustedReadersOfDinner:set = set() +trustedChat:int = -1001541451710 +autoCmdList:bool = False +autoCmdRemove:bool = False +api:str = None +api4File:str = None + + +## +## +## 从命令行与环境变量读取启动参数值 + +i = 1; +while (i < len(sys.argv)) : + + if (sys.argv[i].startswith("-")): + + match sys.argv[i] : + case "--outdated-block" | "-ob" : + outdatedBlock = True + i+=1;continue + case "--no-hello" | "-hf" | "--quiet" | "-q" : + showWelcome = False + i+=1;continue + case "--only-hello" | "-ho" | "-o" | "-hi" : + welcomeEchoMode = True + i+=1;continue + case "--version" | "-v" : + versionEchoMode = True + i+=1;continue + case "--token" | "-t" : + i+=1; key = sys.argv[i] + i+=1;continue + case "--username" | "-u" : + i+=1; username = sys.argv[i] + i+=1;continue + case "--master" | "-mm" : + i+=1; master = int(sys.argv[i]) + i+=1;continue + case "--trusted-chat" | "-trs" : + i+=1; trustedChat = int(sys.argv[i]) + i+=1;continue + case "--trusted-reader-dinner" | "-trsd" : + i+=1; trustedReadersOfDinner.add(int(sys.argv[i])) + i+=1;continue + case "--auto-cmd" | "-cmd" | "-c" : + autoCmdList = True + autoCmdRemove = True + i+=1;continue + case "--auto-cmd-list" | "-ca" : + autoCmdList = True + i+=1;continue + case "--auto-cmd-remove" | "-cr" : + autoCmdRemove = True + i+=1;continue + case "--api" | "-a" : + i+=1; api = sys.argv[i] + i+=1;continue + case "--api-files" | "files-api" | "-af" : + i+=1; api4File = sys.argv[i] + i+=1;continue + + warn(f"Can't understand arg to some meaning :\n {sys.argv[i]}") + i+=1 + + +propToken:str = None +'''从系统环境变量设置的 bot token 值''' +propTokenKey:str = None +'''表明 bot token 值的来源是哪个系统环境变量''' + +for iKey in [prop_name_token_tg_key, prop_name_token_morny_key] : + if (os.getenv(iKey) != None) : + propToken = os.getenv(iKey) + propTokenKey = iKey + +## +## +## 启动参数的检查和处理 + +if versionEchoMode : + info(f"""Morny Cono Version +- version : + {Coeur_Def.VERSION} {Coeur_Def.CODE.upper()} +- md5hash : + +- rw.time : + {Coeur_Def.TIMETAG} [UTC+8]""" + ); exit() + +if showWelcome : info(morny_hello_text()) +if welcomeEchoMode : exit() + +info(f"""start.py Executed >>> +- version {Coeur_Def.VERSION} [{Coeur_Def.TIMETAG}] +- Morny {Coeur_Def.CODE.upper()}""") + +## +## +## Coeur 参数检查以及正式呼叫主程序 + +if (propToken != None) : + key = propToken + info(f"Parameter set by EnvVar ${propTokenKey}") +if (key == None) : + info("Parameter required has no value:\n --token.") + exit() +threading.current_thread().name = thread_morny_init +#todo call coeur main