0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-08-31 14:28:50 +09:00
yude.jp/pages/components/DiscordPlaying.js

29 lines
833 B
JavaScript
Raw Normal View History

2021-05-25 16:45:46 +09:00
import React from "react";
import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
2021-05-28 10:42:03 +09:00
import useRequest from '../lib/useRequest'
2021-05-25 16:45:46 +09:00
const App = () => {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("common")
2021-05-28 10:42:03 +09:00
const { data } = useRequest({
url: 'https://discord.com/api/guilds/723409709306216498/widget.json'
})
if (data === undefined){
console.log("Discord API: データの取得に失敗しました。 / Failed to retrieve data.")
return <p></p>
}else{
const str = JSON.stringify(data)
const yes_playing = t('yes_playing', {playing: data.members[0].game.name})
if (str.indexOf("game") !== -1){
2021-05-25 16:45:46 +09:00
return <p>{yes_playing}</p>
}else{
2021-05-28 10:42:03 +09:00
return <p></p>
2021-05-25 16:45:46 +09:00
}
2021-05-28 10:42:03 +09:00
}
2021-05-25 16:45:46 +09:00
};
export default App;