forked from DiscordBots/lilJudd
feat: save messageids to database
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
3aeefefd32
commit
03fa8a51a7
1 changed files with 23 additions and 6 deletions
|
@ -30,9 +30,12 @@ import net.moonleay.lilJudd.Bot
|
||||||
import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData
|
import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData
|
||||||
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
|
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
|
||||||
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
|
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
|
||||||
import net.moonleay.lilJudd.util.ButtonUtil
|
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
|
||||||
|
import net.moonleay.lilJudd.util.EmbedUtil
|
||||||
import net.moonleay.lilJudd.util.Logger
|
import net.moonleay.lilJudd.util.Logger
|
||||||
import net.moonleay.lilJudd.util.MessageUtil
|
import net.moonleay.lilJudd.util.MessageUtil
|
||||||
|
import net.moonleay.lilJudd.util.TimeUtil
|
||||||
|
import org.jetbrains.exposed.sql.insert
|
||||||
import org.jetbrains.exposed.sql.selectAll
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
@ -62,6 +65,8 @@ object TimeManager {
|
||||||
// ChannelID, Data
|
// ChannelID, Data
|
||||||
val roleList = mutableMapOf<Snowflake, PlanningNotifierRolesData>()
|
val roleList = mutableMapOf<Snowflake, PlanningNotifierRolesData>()
|
||||||
|
|
||||||
|
var msgStr = ""
|
||||||
|
|
||||||
transaction {
|
transaction {
|
||||||
for (tp in TimePlanningChannels.selectAll()) {
|
for (tp in TimePlanningChannels.selectAll()) {
|
||||||
channelList[Snowflake(tp[TimePlanningChannels.channelid])] =
|
channelList[Snowflake(tp[TimePlanningChannels.channelid])] =
|
||||||
|
@ -74,9 +79,9 @@ object TimeManager {
|
||||||
pnr[PlanningNotifierRoles.serverid],
|
pnr[PlanningNotifierRoles.serverid],
|
||||||
pnr[PlanningNotifierRoles.channelid],
|
pnr[PlanningNotifierRoles.channelid],
|
||||||
pnr[PlanningNotifierRoles.hastimeroleid],
|
pnr[PlanningNotifierRoles.hastimeroleid],
|
||||||
pnr[PlanningNotifierRoles.wantstobenotifid]
|
pnr[PlanningNotifierRoles.wantstobenotifiedid]
|
||||||
)
|
)
|
||||||
Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifid]}}")
|
Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifiedid]}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.out("${channelList.count()} Channels to notify with ${roleList.count()} Roles to ping!")
|
Logger.out("${channelList.count()} Channels to notify with ${roleList.count()} Roles to ping!")
|
||||||
|
@ -86,7 +91,8 @@ object TimeManager {
|
||||||
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(ch)!!
|
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(ch)!!
|
||||||
c.createMessage {
|
c.createMessage {
|
||||||
if (roleList[ch] != null) {
|
if (roleList[ch] != null) {
|
||||||
this.content = "<@&${Snowflake(roleList[ch]?.wantstobenotifid!!)}>"
|
this.content =
|
||||||
|
"The weekly planning starts now <@&${Snowflake(roleList[ch]?.wantstobenotifid!!)}>"
|
||||||
}
|
}
|
||||||
this.embeds.add(
|
this.embeds.add(
|
||||||
MessageUtil.getEmbed(
|
MessageUtil.getEmbed(
|
||||||
|
@ -100,7 +106,7 @@ object TimeManager {
|
||||||
delay(2000)
|
delay(2000)
|
||||||
var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(4).withMinute(0).withSecond(0)
|
var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(4).withMinute(0).withSecond(0)
|
||||||
repeat(7) {
|
repeat(7) {
|
||||||
c.createMessage {
|
val msg = c.createMessage {
|
||||||
this.embeds.add(
|
this.embeds.add(
|
||||||
MessageUtil.getEmbedWithTable(
|
MessageUtil.getEmbedWithTable(
|
||||||
Color(0X4C4645),
|
Color(0X4C4645),
|
||||||
|
@ -115,14 +121,25 @@ object TimeManager {
|
||||||
)
|
)
|
||||||
|
|
||||||
this.actionRow {
|
this.actionRow {
|
||||||
this.components.addAll(ButtonUtil.getTimePlannerButtons().components)
|
this.components.addAll(EmbedUtil.getTimePlannerButtons().components)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msgStr += "${it}:${msg.id.value};"
|
||||||
then = then.plusDays(1).withHour(4).withMinute(0).withSecond(0)
|
then = then.plusDays(1).withHour(4).withMinute(0).withSecond(0)
|
||||||
Logger.out("Finished sending day $it")
|
Logger.out("Finished sending day $it")
|
||||||
|
|
||||||
delay(1000)
|
delay(1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the message ids
|
||||||
|
transaction {
|
||||||
|
TimePlanningMessages.insert {
|
||||||
|
it[TimePlanningMessages.serverid] = c.data.guildId.value.toString()
|
||||||
|
it[TimePlanningMessages.channelid] = c.id.value.toString()
|
||||||
|
it[TimePlanningMessages.weekstamp] = TimeUtil.getWeekStamp().toOffsetDateTime().toString()
|
||||||
|
it[TimePlanningMessages.messageids] = msgStr
|
||||||
|
} get PlanningNotifierRoles.id
|
||||||
|
}
|
||||||
Logger.out("Finished with ${c.data.guildId.value}")
|
Logger.out("Finished with ${c.data.guildId.value}")
|
||||||
}
|
}
|
||||||
Logger.out("Done! Until next Monday! <3 ")
|
Logger.out("Done! Until next Monday! <3 ")
|
||||||
|
|
Loading…
Reference in a new issue