🤖 Ready State

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2023-05-13 10:15:57 +05:30
parent 27ff15a8aa
commit 0998cb71d8
Signed by: bravo68web
GPG Key ID: F5671FD7BCB9917A
8 changed files with 25 additions and 151 deletions

View File

@ -29,6 +29,7 @@
"discord.js": "^14.11.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"fastify": "^4.17.0",
"gifencoder": "^2.0.1",
"glob": "^10.2.3",
"graphql": "^16.6.0",
@ -42,7 +43,8 @@
"zod": "^3.21.4"
},
"scripts": {
"dev": "nodemon --watch 'src/**/*.ts' --exec node --loader @esbuild-kit/esm-loader src/index.ts",
"start": "node --loader @esbuild-kit/esm-loader src/index.ts"
"dev": "NODE_ENV=development nodemon --watch 'src/**/*.ts' --exec node --loader @esbuild-kit/esm-loader src/index.ts",
"start": "node --loader @esbuild-kit/esm-loader src/index.ts",
"build": "tsc"
}
}

View File

@ -1,6 +1,6 @@
import { Client, Collection, GatewayIntentBits, Partials } from 'discord.js'
// import './http/server';
import './server'
import { loadSlashCommand, loadTextCommand } from './loaders/command'
import { loadDiscordEvent } from './loaders/event'

View File

@ -1,143 +0,0 @@
import axios from 'axios'
import { EmbedBuilder } from 'discord.js'
import { parseStringPromise } from 'xml2js'
import type { TextCommand } from '../../../sturctures/command'
export const command: TextCommand = {
data: {
name: 'weather',
description: 'Get weather.',
directMessageAllowed: true,
cooldownInterval: 10 * 1000,
},
run: async ({ message, args }) => {
const embed = new EmbedBuilder()
const targetLocation = args.join(' ')
if (!targetLocation) {
return
}
try {
const url = 'https://weather.service.msn.com/find.aspx'
const response = await axios.get(url, {
params: {
src: 'outlook',
weadegreetype: 'C',
culture: 'en-US',
weasearchstr: targetLocation,
},
timeout: 10_000,
})
const responseData = response.data as string
if (!responseData.includes('<')) {
if (responseData.search(/not found/i) !== -1) {
throw new Error('Location not found!')
}
throw new Error('Unknown error!')
}
const data = await parseStringPromise(responseData)
interface CurrentWeather {
$: {
temperature: string
skytext: string
date: string
observationtime: string
observationpoint: string
feelslike: string
humidity: string
winddisplay: string
day: string
shortday: string
windspeed: string
}
}
interface WeatherData {
$: {
weatherlocationname: string
timezone: string
url: string
imagerelativeurl: string
degreetype: string
entityid: string
}
current: CurrentWeather[]
}
const weatherData: WeatherData = data.weatherdata.weather[0]
embed
.setTitle(
`${weatherData.$.weatherlocationname}'s Current Weather:`
)
.setDescription(
`More Information: [HERE](${weatherData.$.url})`
)
.setFooter({
text: `ID: ${weatherData.$.entityid}`,
})
.addFields([
{
name: 'Date',
value: `${weatherData.current[0].$.date} (${weatherData.current[0].$.day})`,
inline: false,
},
{
name: 'Time Zone',
value: `UTC${
weatherData.$.timezone.startsWith('-')
? weatherData.$.timezone
: '+' + weatherData.$.timezone
}`,
inline: true,
},
{
name: 'Status',
value: weatherData.current[0].$.skytext,
inline: true,
},
{
name: 'Temperature',
value: weatherData.current[0].$.temperature + '°C',
inline: true,
},
{
name: 'Feels like',
value: weatherData.current[0].$.feelslike + '°C',
inline: true,
},
{
name: 'Humidity',
value: weatherData.current[0].$.humidity,
inline: true,
},
{
name: 'Windspeed',
value: weatherData.current[0].$.winddisplay,
inline: true,
},
])
await message.reply({
embeds: [embed],
})
} catch (error) {
if (error instanceof Error) {
embed.setTitle(error.message)
await message.reply({
embeds: [embed],
})
}
}
},
}

View File

@ -9,7 +9,7 @@ import { getCommandHelpInfo, resembleCommandCheck } from '../utils/cmds'
import { isDev } from '../utils/constants'
import { parseMsToVisibleText } from '../utils/formatters'
import { callbackEmbed } from '../utils/messages'
import MYGuildConfig from '../../config/guild.config'
import MYGuildConfig from '../utils/guild.config'
async function reject(message: Message, usage: string, missing: string) {
const postMessage = await message.reply({

View File

@ -21,6 +21,6 @@ export const event: DiscordEvent = {
})
}, 15 * 1000)
console.log('Bot is in ready status!')
console.log('🤖 Bot is in ready status!')
},
}

View File

@ -0,0 +1,13 @@
import fastify from 'fastify'
import client from '../bot'
const server = fastify()
server.get('/', () => {
return client.user?.username + ' is ready !!'
})
await server.listen({
port: Number(process.env.PORT ?? '3000'),
host: '0.0.0.0',
})

View File

@ -1,4 +1,4 @@
import { GuildConfig } from '../src/sturctures/database'
import { GuildConfig } from '../sturctures/database'
const MYGuildConfig: GuildConfig = {
prefix: 'd!',

View File

@ -30,8 +30,10 @@
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "esnext"
"target": "esnext",
"outDir": "./dist"
},
"display": "Default tsconfig.json",
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"include": ["./**/*.ts", "./**/*.tsx", "./**/*.json", "./**/*.js"]
}