-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8c024d
commit 76eea63
Showing
9 changed files
with
192 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export const en = { | ||
chatgame: { | ||
welcomeMessage: `Welcome to ChatGame! 🥳 | ||
Choose the game or action 👇`, | ||
playingOnTwitch: '👾 Playing on Twitch', | ||
}, | ||
woodland: { | ||
welcomeMessage: `Welcome to Woodlands! 🥳 | ||
One of the tasks is to accompany the Machine from point A to point B. Along the way, obstacles may appear. Tap them! 👆💪 | ||
Participate in events, invite friends, collect Coins and unlock manually created characters. 🤴🎅🐶`, | ||
title: '🌲 Woodlands: Online Game', | ||
play: '🎮 Play', | ||
developingGameOnTwitch: '👾 Developing game on Twitch', | ||
website: '👨💻 Project website', | ||
}, | ||
subscribeToChannel: '📢 Subscribe to the channel', | ||
defaultBotReply: 'I dont know how to reply to messages yet. Contact @hmbanan666 if you have any questions.', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { en } from './en' | ||
import { ru } from './ru' | ||
|
||
export type Dictionary = typeof en | ||
|
||
export function dictionary(locale: string | undefined = 'en'): Dictionary { | ||
switch (locale) { | ||
case 'ru': | ||
return ru | ||
default: | ||
return en | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Dictionary } from '.' | ||
|
||
export const ru: Dictionary = { | ||
chatgame: { | ||
welcomeMessage: `Добро пожаловать в ChatGame! 🥳 | ||
Выбери игру или действие 👇`, | ||
playingOnTwitch: '👾 Играем на Twitch', | ||
}, | ||
woodland: { | ||
welcomeMessage: `Добро пожаловать в Woodlands! 🥳 | ||
Одна из задач - сопровождать Машину из точки А в точку Б. По пути могут встречаться препятствия. Тапай их! 👆💪 | ||
Участвуй в событиях, приглашай друзей, добывай Монеты и разблокируй вручную созданных персонажей. 🤴🎅🐶`, | ||
title: '🌲 Woodlands: Онлайн-игра', | ||
play: '🎮 Играть', | ||
developingGameOnTwitch: '👾 Улучшаем игру на Twitch', | ||
website: '👨💻 Веб-сайт проекта', | ||
}, | ||
subscribeToChannel: '📢 Подпишись на канал', | ||
defaultBotReply: 'Я пока не умею отвечать на сообщения. Свяжись с @hmbanan666, если есть вопросы.', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { gameBot } from './bot' | ||
|
||
export async function sendNotificationToAllPlayers() { | ||
const telegramProfiles = await prisma.telegramProfile.findMany() | ||
|
||
for (const telegramProfile of telegramProfiles) { | ||
try { | ||
await gameBot.api.sendMessage(telegramProfile.telegramId, `Появилась возможность активировать предметы в Инвентаре! 🎉 | ||
Кладу тебе в Инвентарь Банан 🍌 Можешь его съесть и получить награду.`, { | ||
reply_markup: { | ||
inline_keyboard: [ | ||
[{ text: '🎮 Открыть игру', url: `tg://resolve?domain=woodlandsgamebot&appname=game&startapp=banana` }], | ||
], | ||
}, | ||
}) | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Bot } from 'grammy' | ||
import { dictionary } from './locale' | ||
|
||
const logger = useLogger('telegram') | ||
const { telegramBotToken, telegramAdminId } = useRuntimeConfig() | ||
|
||
const gameChannelUrl = 'https://t.me/chatgamespace' | ||
const woodlandsBotUrl = 'https://t.me/WoodlandsGameBot' | ||
const twitchUrl = 'https://twitch.tv/hmbanan666' | ||
|
||
const bot = new Bot(telegramBotToken) | ||
|
||
bot.on('message:text', async (ctx) => { | ||
const locale = ctx.message.from.language_code | ||
|
||
if (ctx.hasCommand('start')) { | ||
// Welcome message with buttons | ||
await ctx.reply( | ||
dictionary(locale).chatgame.welcomeMessage, | ||
{ | ||
reply_markup: { | ||
inline_keyboard: [ | ||
[{ text: dictionary(locale).woodland.title, url: woodlandsBotUrl }], | ||
[{ text: dictionary(locale).subscribeToChannel, url: gameChannelUrl }], | ||
[{ text: dictionary(locale).chatgame.playingOnTwitch, url: twitchUrl }], | ||
], | ||
}, | ||
}, | ||
) | ||
|
||
return | ||
} | ||
|
||
logger.log(ctx.message.from.id, ctx.message.text) | ||
ctx.reply(dictionary(locale).defaultBotReply) | ||
}) | ||
|
||
async function notifyAdmin(message: string) { | ||
return bot.api.sendMessage(telegramAdminId, message) | ||
} | ||
|
||
export { bot, notifyAdmin } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.