-
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.
* Update gunun sorusu flow update gunun sorusu flow * update for dev env * wip * wip * enhance commands --------- Co-authored-by: Can Sirin <[email protected]>
- Loading branch information
Showing
17 changed files
with
297 additions
and
177 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
CLIENT_ID=client-id | ||
GUILD_ID=guild-id | ||
DISCORD_TOKEN=discord-token | ||
CHATGPT_API_KEY=get-your-chatgpt-key | ||
GIDENLER_CHANNEL_ID=channel-id | ||
GIDENLER_VIDEO_LINK=youtube-link | ||
SORU_CEVAP_CHANNEL_ID=channel-id | ||
GUNAYDIN_CHANNEL_ID=channel-id |
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,15 @@ | ||
name: Fly deploy | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: superfly/flyctl-actions/setup-flyctl@master | ||
- run: flyctl deploy --app bot-dev --remote-only | ||
env: | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
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,23 @@ | ||
# fly.toml app configuration file generated for kampus-discord-bot on 2023-11-26T10:45:21-08:00 | ||
# | ||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file. | ||
# | ||
|
||
app = "bot-dev" | ||
primary_region = "sjc" | ||
|
||
[build] | ||
dockerfile = "Dockerfile" | ||
|
||
[http_service] | ||
internal_port = 3000 | ||
force_https = true | ||
auto_stop_machines = true | ||
auto_start_machines = true | ||
min_machines_running = 1 | ||
processes = ["app"] | ||
|
||
[[vm]] | ||
cpu_kind = "shared" | ||
cpus = 1 | ||
memory_mb = 512 |
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 |
---|---|---|
@@ -1,36 +1,83 @@ | ||
import { CommandInteraction, Constants, SlashCommandBuilder, TextChannel } from "discord.js"; | ||
import { GUNAYDIN_CHANNEL_ID } from "../../config"; | ||
import _ from "lodash"; | ||
import { | ||
CommandInteraction, | ||
Message, | ||
SlashCommandBuilder, | ||
TextChannel, | ||
messageLink, | ||
} from "discord.js"; | ||
import { fetchMessages } from "../features/fetch-messages"; | ||
import { isTodayDailyQuestionFound } from "../features/is-daily-msg-exist"; | ||
|
||
module.exports = { | ||
const dailyMorningQuestion = { | ||
data: new SlashCommandBuilder() | ||
.setName("gunun-sorusu") | ||
.setDescription("Günün sorusunu oluşturur."), | ||
.setDescription("Creates 'Günün sorusu' thread.") | ||
.addNumberOption((option) => option.setName("count").setDescription("Günün sorusu sayısı")), | ||
async execute(interaction: CommandInteraction) { | ||
const channel = (await interaction.client.channels.fetch(GUNAYDIN_CHANNEL_ID)) as TextChannel; | ||
|
||
const today = new Date(); | ||
const options = { | ||
month: "long", | ||
day: "numeric", | ||
} as Intl.DateTimeFormatOptions; | ||
const formattedDate = new Intl.DateTimeFormat("tr-TR", options).format(today); | ||
|
||
const thread = await channel.threads.create({ | ||
name: "Günün Sorusu - " + formattedDate, | ||
}); | ||
|
||
const geyik = `<:geyik:1161771822350602260>`; | ||
const threadMention = `<#${thread.id}>`; | ||
const message = await channel.send(threadMention); | ||
const threadMessage = await thread.send( | ||
`Volkan abi ve geyikler günün sorusunu soruyor!\n ${geyik} ${geyik} ${geyik} ${geyik} ${geyik} ${geyik}` | ||
); | ||
const messagePin = await message.pin(); | ||
Promise.all([threadMessage, messagePin, message]); | ||
|
||
interaction.reply({ | ||
content: `Günün sorusu başarıyla oluşturuldu! Thread icin: ${threadMention}`, | ||
ephemeral: true, | ||
}); | ||
if (!process.env.GUNAYDIN_CHANNEL_ID) { | ||
throw new Error("GUNAYDIN_CHANNEL_ID environment variable is not set."); | ||
} | ||
|
||
const channel = (await interaction.client.channels.fetch( | ||
process.env.GUNAYDIN_CHANNEL_ID ?? "" | ||
)) as TextChannel; | ||
const botId = "1183616536682958899"; | ||
|
||
let messages = (await fetchMessages( | ||
interaction.client, | ||
process.env.GUNAYDIN_CHANNEL_ID, | ||
1, | ||
botId | ||
)) as Message[]; | ||
|
||
if (!messages) { | ||
console.log("No messages found sent by the bot."); | ||
messages = []; | ||
} | ||
|
||
const [isFound, m, c] = isTodayDailyQuestionFound(messages); | ||
const count = (interaction.options.get("count")?.value as number) ?? c; | ||
|
||
if (isFound && m) { | ||
await interaction.deferReply({ | ||
ephemeral: true, | ||
}); | ||
await interaction.editReply({ | ||
content: `Günün sorusu zaten oluşturulmuş! ${messageLink( | ||
m.channelId, | ||
m.id, | ||
m.guildId ?? "" | ||
)}`, | ||
}); | ||
} else { | ||
const questionTitle = `Günün Sorusu - ${count}`; | ||
const threadMention = buildDailyMorningQuestion(channel, questionTitle); | ||
await interaction.deferReply({ | ||
ephemeral: true, | ||
}); | ||
await interaction.editReply({ | ||
content: `Günün sorusu başarıyla oluşturuldu! Thread icin: ${threadMention}`, | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
export default dailyMorningQuestion; | ||
|
||
const buildDailyMorningQuestion = async (channel: TextChannel, questionTitle: string) => { | ||
const thread = await channel.threads.create({ | ||
name: questionTitle, | ||
}); | ||
|
||
const geyik = `<:geyik:1161771822350602260>`; | ||
const threadMention = `<#${thread.id}>`; | ||
const message = await channel.send(threadMention); | ||
const threadMessage = await thread.send( | ||
`Volkan abi ve geyikler günün sorusunu soruyor!\n ${geyik} ${geyik} ${geyik} ${geyik} ${geyik} ${geyik}` | ||
); | ||
const messagePin = await message.pin(); | ||
Promise.all([threadMessage, messagePin, message]); | ||
|
||
return threadMention; | ||
}; |
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.