commit
This commit is contained in:
parent
943ecc44c1
commit
1bbbf05545
2 changed files with 60 additions and 21 deletions
7
app.js
7
app.js
|
@ -6,6 +6,7 @@ const { getJoke } = require('./libs/dadJokes');
|
|||
const { rtag, r34 } = require('./libs/rule34');
|
||||
const { addToLogs, isTrue, image_search } = require('./libs/botTools');
|
||||
const { rockPaperScissorsAgainstBot } = require('./libs/games');
|
||||
const { generateImage } = require('./libs/openAi');
|
||||
|
||||
//bot initialization
|
||||
const bot = new Telegraf(process.env.TELEGRAM);
|
||||
|
@ -25,6 +26,8 @@ bot.help(ctx => {
|
|||
-/help
|
||||
Anime command :
|
||||
-/anime
|
||||
AI Generated image command :
|
||||
-\`/g <query>\`
|
||||
Image search command :
|
||||
-\`/s <query>\`
|
||||
Dad jokes command :
|
||||
|
@ -95,5 +98,9 @@ bot.command('rps', ctx => {
|
|||
rockPaperScissorsAgainstBot(ctx.message.text.slice(+5), ctx, bot)
|
||||
})
|
||||
|
||||
bot.command('g', ctx => {
|
||||
generateImage(ctx.message.text.slice(+3), ctx, bot)
|
||||
})
|
||||
|
||||
//bot launch
|
||||
bot.launch();
|
32
libs/openAi.js
Normal file
32
libs/openAi.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const { Configuration, OpenAIApi } = require("openai");
|
||||
const { addToLogs } = require('./botTools');
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: process.env.OPENAI,
|
||||
});
|
||||
|
||||
const openai = new OpenAIApi(configuration);
|
||||
|
||||
function generateImage(query, ctx, bot) {
|
||||
const image = openai.createImage({
|
||||
prompt: query,
|
||||
n: 1,
|
||||
size: "1024x1024",
|
||||
response_format : 'url'
|
||||
})
|
||||
|
||||
console.log("--> generating image for the querry" + query);
|
||||
addToLogs("--> generating image for the querry" + query)
|
||||
bot.telegram.sendMessage(ctx.chat.id, "Generating the image.", {});
|
||||
|
||||
image.then((res) => {
|
||||
url = res.data.data[0].url
|
||||
|
||||
bot.telegram.sendPhoto(ctx.chat.id, url, {"caption": "This is a generated image for the querry : " + query}).catch((err) => {
|
||||
bot.telegram.sendMessage(ctx.chat.id, "Something went wrong.", {});
|
||||
console.log("--> error while sending the image : " + err);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { generateImage };
|
Loading…
Add table
Add a link
Reference in a new issue