commit
This commit is contained in:
parent
943ecc44c1
commit
1bbbf05545
2 changed files with 60 additions and 21 deletions
49
app.js
49
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);
|
||||
|
@ -20,27 +21,29 @@ bot.command('start', ctx => {
|
|||
bot.help(ctx => {
|
||||
const helpMessage =
|
||||
`
|
||||
This is the help message :
|
||||
Help command :
|
||||
-/help
|
||||
Anime command :
|
||||
-/anime
|
||||
Image search command :
|
||||
-\`/s <query>\`
|
||||
Dad jokes command :
|
||||
-/dadjoke
|
||||
Rock Paper Scissors command :
|
||||
-\`/rps <rock/paper/scissors>\`
|
||||
Rule34 tag command :
|
||||
-\`/rtag <querry>\`
|
||||
Rule 34 image search :
|
||||
-\`/r34 <tag>\`
|
||||
Truce command :
|
||||
-/truce (reply to a message with that command to verify it)
|
||||
Suggest command :
|
||||
-\`/suggest <suggestion>\` (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk)
|
||||
Github link command :
|
||||
-/github
|
||||
This is the help message :
|
||||
Help command :
|
||||
-/help
|
||||
Anime command :
|
||||
-/anime
|
||||
AI Generated image command :
|
||||
-\`/g <query>\`
|
||||
Image search command :
|
||||
-\`/s <query>\`
|
||||
Dad jokes command :
|
||||
-/dadjoke
|
||||
Rock Paper Scissors command :
|
||||
-\`/rps <rock/paper/scissors>\`
|
||||
Rule34 tag command :
|
||||
-\`/rtag <querry>\`
|
||||
Rule 34 image search :
|
||||
-\`/r34 <tag>\`
|
||||
Truce command :
|
||||
-/truce (reply to a message with that command to verify it)
|
||||
Suggest command :
|
||||
-\`/suggest <suggestion>\` (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk)
|
||||
Github link command :
|
||||
-/github
|
||||
`
|
||||
bot.telegram.sendMessage(ctx.chat.id, helpMessage, {parse_mode: "Markdown"})
|
||||
console.log('--> sent the help message')
|
||||
|
@ -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