CoolFace
Apppublic

stoneFree/bingo

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
chat-notification.tsx78 linesDownload Raw Back to components
1import { useEffect } from 'react'2import Image from 'next/image'3 4import IconWarning from '@/assets/images/warning.svg'5import { ChatError, ErrorCode, ChatMessageModel } from '@/lib/bots/bing/types'6import { ExternalLink } from './external-link'7import { useBing } from '@/lib/hooks/use-bing'8 9export interface ChatNotificationProps extends Pick<ReturnType<typeof useBing>, 'bot'> {10  message?: ChatMessageModel11}12 13function getAction(error: ChatError, reset: () => void) {14  if (error.code === ErrorCode.THROTTLE_LIMIT) {15    reset()16    return (17      <div>18        你已达到每日最大发送消息次数,请<a href={`#dialog="settings"`}>更换账号</a>或隔一天后重试19      </div>20    )21  }22  if (error.code === ErrorCode.BING_FORBIDDEN) {23    return (24      <ExternalLink href="https://bing.com/new">25        你的账号已在黑名单,请尝试更换账号及申请解封26      </ExternalLink>27    )28  }29  if (error.code === ErrorCode.CONVERSATION_LIMIT) {30    return (31      <div>32        当前话题已中止,请点33        <a href={`#dialog="reset"`}>重新开始</a>34        开启新的对话35      </div>36    )37  }38  if (error.code === ErrorCode.BING_CAPTCHA) {39    return (40      <ExternalLink href="https://www.bing.com/turing/captcha/challenge">41        点击通过人机验证42      </ExternalLink>43    )44  }45  if (error.code === ErrorCode.BING_UNAUTHORIZED) {46    reset()47    return (48      <a href={`#dialog="settings"`}>没有获取到身份信息或身份信息失效,点此重新设置</a>49    )50  }51  return error.message52}53 54export function ChatNotification({ message, bot }: ChatNotificationProps) {55  useEffect(() => {56    window.scrollBy(0, 2000)57  }, [message])58 59  if (!message?.error) return60 61  return (62    <div63      className="notification-container"64    >65      <div className="bottom-notifications">66        <div className="inline-type with-decorative-line">67          <div className="text-container mt-1">68            <div className="title inline-flex items-start">69              <Image alt="error" src={IconWarning} width={20} className="mr-1 mt-1" />70              {getAction(message.error, () => bot.resetConversation())}71            </div>72          </div>73        </div>74      </div>75    </div>76  )77}78