Skip to content

Commit

Permalink
Merge pull request #491 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Add twitter second message
  • Loading branch information
Ziedelth committed May 24, 2024
2 parents 7903eb9 + 7e5e846 commit a3ad9c9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enum class ConfigPropertyKey(val key: String) {
CHECK_CRUNCHYROLL_SIMULCASTS("check_crunchyroll_simulcasts"),
BSKY_IDENTIFIER("bsky_identifier"),
BSKY_PASSWORD("bsky_password"),
TWITTER_MESSAGE("twitter_message"),
TWITTER_FIRST_MESSAGE("twitter_first_message"),
TWITTER_SECOND_MESSAGE("twitter_second_message"),
THREADS_USERNAME("threads_username"),
THREADS_PASSWORD("threads_password"),
THREADS_MESSAGE("threads_message"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ class TwitterSocialNetwork : AbstractSocialNetwork() {
login()
if (!isInitialized) return
if (twitter == null) return
val message =
getEpisodeMessage(episodeDto, configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_MESSAGE) ?: "")

val uploadMedia = twitter!!.tweets().uploadMedia(
UUID.randomUUID().toString(),
ByteArrayInputStream(mediaImage)
val uploadMedia = twitter!!.tweets().uploadMedia(UUID.randomUUID().toString(), ByteArrayInputStream(mediaImage))
val firstMessage = getEpisodeMessage(
episodeDto,
configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_FIRST_MESSAGE) ?: ""
)
val firstTweet = twitter!!.v2.createTweet(mediaIds = arrayOf(uploadMedia.mediaId), text = firstMessage)

twitter!!.v2.createTweet(mediaIds = arrayOf(uploadMedia.mediaId), text = message)
val secondMessage = configCacheService.getValueAsString(ConfigPropertyKey.TWITTER_SECOND_MESSAGE)

if (!secondMessage.isNullOrBlank()) {
twitter!!.v2.createTweet(
inReplyToTweetId = firstTweet.id,
text = getEpisodeMessage(episodeDto, secondMessage)
)
}
}

override fun sendCalendar(message: String, calendarImage: ByteArray) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/resources/db/changelog/2024/05/04-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1716574121795"/>
<property global="false" name="author" value="Ziedelth"/>

<changeSet id="${id}-1" author="${author}" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">SELECT COUNT(*)
FROM config
WHERE property_key = 'twitter_first_message'</sqlCheck>
</preConditions>

<update tableName="config">
<column name="property_key" value="twitter_first_message"/>
<where>property_key = 'twitter_message'</where>
</update>
</changeSet>

<changeSet id="${id}-2" author="${author}" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">SELECT COUNT(*)
FROM config
WHERE property_key = 'twitter_second_message'</sqlCheck>
</preConditions>

<insert tableName="config">
<column name="uuid" valueComputed="gen_random_uuid()"/>
<column name="property_key" value="twitter_second_message"/>
<column name="property_value" value=""/>
</insert>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@
<include file="/db/changelog/2024/05/01-changelog.xml"/>
<include file="/db/changelog/2024/05/02-changelog.xml"/>
<include file="/db/changelog/2024/05/03-changelog.xml"/>
<include file="/db/changelog/2024/05/04-changelog.xml"/>
</databaseChangeLog>

0 comments on commit a3ad9c9

Please sign in to comment.