-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Module } from "../../packages/common/mod.ts"; | ||
import { WeatherController } from "./weather.controller.ts"; | ||
|
||
@Module({ | ||
controllers: [WeatherController], | ||
}) | ||
export class BotModule {} |
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,9 @@ | ||
import { TeaFactory } from "../../packages/core/factory.ts"; | ||
import { BotModule } from "./bot.module.ts"; | ||
|
||
function bootstrap() { | ||
const bot = TeaFactory.create(BotModule, "BOT_TOKEN"); | ||
bot.start(); | ||
} | ||
|
||
bootstrap(); |
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,37 @@ | ||
import { | ||
Command, | ||
Context, | ||
Controller, | ||
UpdateType, | ||
} from "../../packages/common/mod.ts"; | ||
|
||
const weatherConditions = ["☀️🥵☀️", "❄️☃️❄️"]; | ||
|
||
@Controller({ updateTypes: [UpdateType.MESSAGE] }) | ||
export class WeatherController { | ||
@Command("forecast") | ||
async forecast(@Context() context: any) { | ||
const randomIndex = getRandomIndex(weatherConditions); | ||
if (randomIndex === 0) { | ||
context.reply("The air is warming up, get ready to swim"); | ||
} else { | ||
context.reply( | ||
"The weather is going to be cold, make sure you have warm clothes", | ||
); | ||
} | ||
await sleep(3000); | ||
return context.reply(weatherConditions[randomIndex]); | ||
} | ||
|
||
@Command("current") | ||
current() { | ||
const randomIndex = getRandomIndex(weatherConditions); | ||
return Promise.resolve(weatherConditions[randomIndex]); | ||
} | ||
} | ||
|
||
const getRandomIndex = (array: unknown[]) => | ||
Math.trunc(Math.random() * array.length); | ||
|
||
const sleep = (time: number) => | ||
new Promise((resolve) => setTimeout(resolve, time)); |
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