commit
This commit is contained in:
parent
943ecc44c1
commit
1bbbf05545
2 changed files with 60 additions and 21 deletions
29
app.js
29
app.js
|
@ -6,6 +6,7 @@ const { getJoke } = require('./libs/dadJokes');
|
||||||
const { rtag, r34 } = require('./libs/rule34');
|
const { rtag, r34 } = require('./libs/rule34');
|
||||||
const { addToLogs, isTrue, image_search } = require('./libs/botTools');
|
const { addToLogs, isTrue, image_search } = require('./libs/botTools');
|
||||||
const { rockPaperScissorsAgainstBot } = require('./libs/games');
|
const { rockPaperScissorsAgainstBot } = require('./libs/games');
|
||||||
|
const { generateImage } = require('./libs/openAi');
|
||||||
|
|
||||||
//bot initialization
|
//bot initialization
|
||||||
const bot = new Telegraf(process.env.TELEGRAM);
|
const bot = new Telegraf(process.env.TELEGRAM);
|
||||||
|
@ -20,26 +21,28 @@ bot.command('start', ctx => {
|
||||||
bot.help(ctx => {
|
bot.help(ctx => {
|
||||||
const helpMessage =
|
const helpMessage =
|
||||||
`
|
`
|
||||||
This is the help message :
|
This is the help message :
|
||||||
Help command :
|
Help command :
|
||||||
-/help
|
-/help
|
||||||
Anime command :
|
Anime command :
|
||||||
-/anime
|
-/anime
|
||||||
Image search command :
|
AI Generated image command :
|
||||||
|
-\`/g <query>\`
|
||||||
|
Image search command :
|
||||||
-\`/s <query>\`
|
-\`/s <query>\`
|
||||||
Dad jokes command :
|
Dad jokes command :
|
||||||
-/dadjoke
|
-/dadjoke
|
||||||
Rock Paper Scissors command :
|
Rock Paper Scissors command :
|
||||||
-\`/rps <rock/paper/scissors>\`
|
-\`/rps <rock/paper/scissors>\`
|
||||||
Rule34 tag command :
|
Rule34 tag command :
|
||||||
-\`/rtag <querry>\`
|
-\`/rtag <querry>\`
|
||||||
Rule 34 image search :
|
Rule 34 image search :
|
||||||
-\`/r34 <tag>\`
|
-\`/r34 <tag>\`
|
||||||
Truce command :
|
Truce command :
|
||||||
-/truce (reply to a message with that command to verify it)
|
-/truce (reply to a message with that command to verify it)
|
||||||
Suggest command :
|
Suggest command :
|
||||||
-\`/suggest <suggestion>\` (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk)
|
-\`/suggest <suggestion>\` (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk)
|
||||||
Github link command :
|
Github link command :
|
||||||
-/github
|
-/github
|
||||||
`
|
`
|
||||||
bot.telegram.sendMessage(ctx.chat.id, helpMessage, {parse_mode: "Markdown"})
|
bot.telegram.sendMessage(ctx.chat.id, helpMessage, {parse_mode: "Markdown"})
|
||||||
|
@ -95,5 +98,9 @@ bot.command('rps', ctx => {
|
||||||
rockPaperScissorsAgainstBot(ctx.message.text.slice(+5), ctx, bot)
|
rockPaperScissorsAgainstBot(ctx.message.text.slice(+5), ctx, bot)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
bot.command('g', ctx => {
|
||||||
|
generateImage(ctx.message.text.slice(+3), ctx, bot)
|
||||||
|
})
|
||||||
|
|
||||||
//bot launch
|
//bot launch
|
||||||
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