mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 05:17:10 +00:00
fix: time
This commit is contained in:
parent
7be0e61e14
commit
3318ac04d8
3 changed files with 65 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import { Chaite } from 'chaite'
|
|||
import { intoUserMessage, toYunzai } from '../utils/message.js'
|
||||
import common from '../../../lib/common/common.js'
|
||||
import { getGroupContextPrompt } from '../utils/group.js'
|
||||
import {formatTimeToBeiJing} from '../utils/common.js'
|
||||
|
||||
export class bym extends plugin {
|
||||
constructor () {
|
||||
|
|
@ -66,6 +67,7 @@ export class bym extends plugin {
|
|||
}
|
||||
sendMessageOption.systemOverride = ChatGPTConfig.bym.presetPrefix + sendMessageOption.systemOverride
|
||||
}
|
||||
sendMessageOption.systemOverride = `Current Time: ${formatTimeToBeiJing(new Date().getTime())}\n` + sendMessageOption.systemOverride
|
||||
if (ChatGPTConfig.bym.temperature >= 0) {
|
||||
sendMessageOption.temperature = ChatGPTConfig.bym.temperature
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,64 @@ import * as crypto from 'node:crypto'
|
|||
export function md5 (str) {
|
||||
return crypto.createHash('md5').update(str).digest('hex')
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a timestamp to Beijing time (UTC+8)
|
||||
* @param {number|string} timestamp - Timestamp in milliseconds or seconds
|
||||
* @param {string} [format='YYYY-MM-DD HH:mm:ss'] - Output format
|
||||
* @returns {string} Formatted Beijing time
|
||||
*/
|
||||
export function formatTimeToBeiJing (timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
// Handle string timestamp
|
||||
if (typeof timestamp === 'string') {
|
||||
timestamp = parseInt(timestamp)
|
||||
}
|
||||
|
||||
// Automatically determine if timestamp is in seconds or milliseconds
|
||||
// If timestamp represents a date before 2000, assume it's in milliseconds
|
||||
if (timestamp.toString().length <= 10) {
|
||||
// Convert seconds to milliseconds
|
||||
timestamp = timestamp * 1000
|
||||
}
|
||||
|
||||
// Create date object with the timestamp
|
||||
const date = new Date(timestamp)
|
||||
|
||||
// Calculate Beijing time (UTC+8)
|
||||
const beijingTime = new Date(date.getTime() + 8 * 60 * 60 * 1000)
|
||||
|
||||
// Format the date according to the specified format
|
||||
return formatDate(beijingTime, format)
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a Date object according to the specified format
|
||||
* @param {Date} date - Date object to format
|
||||
* @param {string} format - Format string (YYYY-MM-DD HH:mm:ss)
|
||||
* @returns {string} Formatted date string
|
||||
*/
|
||||
function formatDate (date, format) {
|
||||
const year = date.getUTCFullYear()
|
||||
const month = padZero(date.getUTCMonth() + 1)
|
||||
const day = padZero(date.getUTCDate())
|
||||
const hours = padZero(date.getUTCHours())
|
||||
const minutes = padZero(date.getUTCMinutes())
|
||||
const seconds = padZero(date.getUTCSeconds())
|
||||
|
||||
return format
|
||||
.replace('YYYY', year)
|
||||
.replace('MM', month)
|
||||
.replace('DD', day)
|
||||
.replace('HH', hours)
|
||||
.replace('mm', minutes)
|
||||
.replace('ss', seconds)
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads a number with leading zero if needed
|
||||
* @param {number} num - Number to pad
|
||||
* @returns {string} Padded number string
|
||||
*/
|
||||
function padZero (num) {
|
||||
return num < 10 ? '0' + num : num.toString()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { getBotFramework } from './bot.js'
|
||||
import ChatGPTConfig from '../config/config.js'
|
||||
import {formatTimeToBeiJing} from './common.js'
|
||||
|
||||
export class GroupContextCollector {
|
||||
/**
|
||||
|
|
@ -132,7 +133,7 @@ export async function getGroupContextPrompt (e, length) {
|
|||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.sender.title}', sender.title || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.time}', chat.time || '-')
|
||||
.replace('${message.time}', formatTimeToBeiJing(chat.time) || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
.replace('${message.messageId}', chat.messageId || '-')
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue