@@ -236,8 +236,77 @@ export const CcfoliaImportAdapter: ImportAdapter = {
236236 } ,
237237} ;
238238
239+ // 菠萝格式
240+ // [YYYY-MM-DD HH:mm:ss] <playerName|account> content
241+ const PINEAPPLE_LOG_REGEX = / ^ \[ ( [ ^ \] ] + ) \] \s + < ( [ ^ > | ] + ) \| ( [ ^ > ] + ) > \s * ( .* ) $ / ;
242+
243+ export const PineappleImportAdapter : ImportAdapter = {
244+ id : 'pineapple-adapter' ,
245+ name : '菠萝日志格式' ,
246+
247+ test : ( sampleLines : string [ ] ) => {
248+ let score = 0 ;
249+ for ( const line of sampleLines ) {
250+ if ( / ^ \[ [ ^ \] ] + \] \s + < [ ^ > | ] + \| [ ^ > ] + > / . test ( line ) ) {
251+ score += 10 ;
252+ }
253+ }
254+ return score ;
255+ } ,
256+
257+ parse : ( text : string ) => {
258+ const lines = text . split ( '\n' ) ;
259+ const rows : ImportRow [ ] = [ ] ;
260+
261+ let currentName : string | null = null ;
262+ let currentAccount : string | null = null ;
263+ let currentTimeStr : string | null = null ;
264+ let contentBuffer : string [ ] = [ ] ;
265+
266+ const flushBuffer = ( ) => {
267+ if ( currentName !== null && contentBuffer . length > 0 ) {
268+ const rawContent = contentBuffer . join ( '\n' ) ;
269+ rows . push ( {
270+ playerName : currentName ,
271+ account : currentAccount || '' ,
272+ time : currentTimeStr
273+ ? parseLogDate ( currentTimeStr )
274+ : undefined ,
275+ content : cleanContent ( rawContent ) ,
276+ } ) ;
277+ }
278+ contentBuffer = [ ] ;
279+ } ;
280+
281+ for ( const line of lines ) {
282+ const match = line . match ( PINEAPPLE_LOG_REGEX ) ;
283+
284+ if ( match ) {
285+ flushBuffer ( ) ;
286+
287+ currentTimeStr = match [ 1 ] . trim ( ) ;
288+ currentName = match [ 2 ] . trim ( ) ;
289+ currentAccount = match [ 3 ] . trim ( ) ;
290+ const contentText = match [ 4 ] ;
291+
292+ if ( contentText ) {
293+ contentBuffer . push ( contentText ) ;
294+ }
295+ } else {
296+ if ( currentName !== null && line . trim ( ) . length > 0 ) {
297+ contentBuffer . push ( line ) ;
298+ }
299+ }
300+ }
301+ flushBuffer ( ) ;
302+
303+ return rows ;
304+ } ,
305+ } ;
306+
239307const ALL_ADAPTERS : ImportAdapter [ ] = [
240308 StandardImportAdapter ,
241309 PaintedLogAdapter ,
242310 CcfoliaImportAdapter ,
311+ PineappleImportAdapter ,
243312] ;
0 commit comments