Skip to content

Commit

Permalink
cleaup
Browse files Browse the repository at this point in the history
  • Loading branch information
sudotx committed Jul 14, 2024
1 parent 6a0ef0a commit a335ba6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 44 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@grammyjs/i18n": "^0.5.0",
"@grammyjs/menu": "^1.0.4",
"@grammyjs/runner": "^1.0.3",
"axios": "^1.7.2",
"dotenv": "^10.0.0",
"envalid": "^7.2.2",
"grammy": "^1.5.0",
Expand Down
88 changes: 65 additions & 23 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@ import 'reflect-metadata'
import 'source-map-support/register'

import sendHelp from '@/handlers/help'
import handleLanguage from '@/handlers/language'
import bot from '@/helpers/bot'
import i18n from '@/helpers/i18n'
import startMongo from '@/helpers/startMongo'
import languageMenu from '@/menus/language'
import attachUser from '@/middlewares/attachUser'
import configureI18n from '@/middlewares/configureI18n'
import { run } from '@grammyjs/runner'
import { ignoreOld, sequentialize } from 'grammy-middlewares'
import axios from 'axios'
import { InlineKeyboard } from 'grammy'
import { ignoreOld, sequentialize } from 'grammy-middlewares'

const mainMenu = new InlineKeyboard()
.text('Get Neko Image', 'get_neko')
.row()
.text('Download Manga', 'download_manga')
.row()
.text('Trigger Something', 'download_manga')

// show the main menu
bot.command('menu', (ctx) => {
ctx.reply('Welcome! Please choose an option:', {
reply_markup: mainMenu
});
});

async function runApp() {
console.log('Starting app...')
Expand All @@ -30,29 +44,33 @@ async function runApp() {
.use(languageMenu)
// Commands
bot.command(['help', 'start'], sendHelp)
bot.command('language', handleLanguage)
bot.command('earn', () => { console.log("Earn Clicked") })
bot.command('download', async (ctx) => {
const mangaName = ctx.message?.text?.split(' ').slice(1).join(' ');
if (!mangaName) {
ctx.reply('Please provide a manga name.');
return;
}
// bot.command('language', handleLanguage)
bot.command('earn', async (ctx) => {
ctx.reply("Okay earning")

})

bot.callbackQuery('get_neko', async (ctx) => {
try {
const mangaData = await fetchManga(mangaName);
if (mangaData.data.length === 0) {
ctx.reply('Manga not found.');
return;
}
const imageUrl = await fetchNeko();

const manga = mangaData.data[0];
ctx.reply(`Found: ${manga.attributes.title.en}`);
// Add code to download and send manga files
await ctx.reply(imageUrl)
} catch (error) {
ctx.reply('An error occurred while fetching manga.');
await ctx.reply('An error occurred while fetching the neko image.');
}
await ctx.answerCallbackQuery();
});
bot.callbackQuery('get_nsfw_neko', async (ctx) => {
try {
const imageUrl = await getNsfwNeko();

await ctx.reply(imageUrl)
} catch (error) {
await ctx.reply('An error occurred while fetching the neko image.');
}
await ctx.answerCallbackQuery();
});

// Errors
bot.catch(console.error)
// Start bot
Expand All @@ -62,9 +80,33 @@ async function runApp() {
}

void runApp()
const fetchManga = async (mangaName: string) => {
const response = await axios.get(`https://api.mangadex.org/manga?title=${mangaName}`);
console.log(response);
return response.data;

const fetchNeko = async (): Promise<string> => {
try {
const response = await axios.get('https://nekos.pro/api/neko', {
headers: {
'Content-Type': 'application/json',
},
});
return response.data.url;
} catch (error) {
console.error('Error fetching neko image:', error);
throw error;
}

};
const getNsfwNeko = async (): Promise<string> => {
try {
const response = await axios.get('https://nekos.pro/api/neko', {
headers: {
'Content-Type': 'application/json',
},
});
return response.data.url;
} catch (error) {
console.error('Error fetching neko image:', error);
throw error;
}

};

0 comments on commit a335ba6

Please sign in to comment.