mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 08:46:15 +00:00
Merge commit 'e75aa21' into stable
This commit is contained in:
commit
e3708c00ad
19
deploy.sh
19
deploy.sh
@ -40,6 +40,9 @@ git commit -m "Bumping the version to $VERSION" Dockerfile
|
||||
echo "Tagging the new version..."
|
||||
git tag -a "$VERSION" -m "Version $VERSION" || error
|
||||
|
||||
echo "Building it..."
|
||||
gradle build || error "Build failed. What did you do?!"
|
||||
|
||||
echo "Checking out stable..."
|
||||
git checkout stable || error
|
||||
|
||||
@ -52,18 +55,15 @@ git push --all || error
|
||||
echo "Pushing tags to Github..."
|
||||
git push --tags || error
|
||||
|
||||
echo "Building it..."
|
||||
gradle build || error "Build failed. What did you do?!"
|
||||
|
||||
echo "Generating a release on Github..."
|
||||
json=$(ruby -e "require 'json'; puts({tag_name: '$VERSION', name: '$VERSION', draft: true, body: \$stdin.read}.to_json)" <<< "$release_notes") || error "Couldn't generate JSON for Github"
|
||||
json=$(ruby -e "require 'json'; puts({tag_name: '$VERSION', name: '$VERSION', body: \$stdin.read}.to_json)" <<< "$release_notes") || error "Couldn't generate JSON for Github"
|
||||
|
||||
json=$(curl $CURL_OPTS https://api.github.com/repos/fabianonline/telegram_backup/releases -XPOST -d "$json") || error "Github failure"
|
||||
|
||||
echo "Uploading telegram_backup.jar to Github..."
|
||||
upload_url=$(jq -r ".upload_url" <<< "$json") || error "Could not parse JSON from Github"
|
||||
upload_url=$(sed 's/{.*}//' <<< "$upload_url")
|
||||
release_url=$(jq -r ".url" <<< "$json") || error "Could not parse JSON from Github"
|
||||
release_url=$(jq -r ".html_url" <<< "$json") || error "Could not parse JSON from Github"
|
||||
curl $CURL_OPTS --header "Content-Type: application/zip" "${upload_url}?name=telegram_backup.jar" --upload-file build/libs/telegram_backup.jar || error "Asset upload to github failed"
|
||||
|
||||
echo "Building the docker image..."
|
||||
@ -73,12 +73,15 @@ echo "Pushing the docker image..."
|
||||
docker push fabianonline/telegram_backup
|
||||
|
||||
echo "Notifying the Telegram group..."
|
||||
release_notes=$(sed 's/\* /• /' <<< "$release_notes")
|
||||
message="Version $VERSION released"$'\n'$'\n'"$release_notes"$'\n'$'\n'"$release_url"
|
||||
release_notes=$(sed 's/\* /• /' | sed 's/&/&/g' | sed 's/</\</g' | sed 's/>/\>/g' <<< "$release_notes")
|
||||
message="<b>Version $VERSION was just released</b>"$'\n'$'\n'"$release_notes"$'\n'$'\n'"$release_url"
|
||||
|
||||
curl https://api.telegram.org/bot${BOT_TOKEN}/sendMessage -XPOST --form "text=<-" --form-string "chat_id=${CHAT_ID}" <<< "$message"
|
||||
curl https://api.telegram.org/bot${BOT_TOKEN}/sendMessage -XPOST --form "text=<-" --form-string "chat_id=${CHAT_ID}" --form-string "parse_mode=HTML" --form-string "disable_web_page_preview=true" <<< "$message"
|
||||
|
||||
echo "Cleaning release_notes.txt..."
|
||||
> release_notes.txt
|
||||
|
||||
echo "Checking out master..."
|
||||
git checkout master
|
||||
|
||||
echo "Done."
|
||||
|
@ -56,7 +56,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
try {
|
||||
val rs = stmt!!.executeQuery("SELECT MAX(message_id) FROM messages WHERE source_type IN ('group', 'dialog')")
|
||||
rs.next()
|
||||
return rs.getInt(1)
|
||||
val result = rs.getInt(1)
|
||||
rs.close()
|
||||
return result
|
||||
} catch (e: SQLException) {
|
||||
return 0
|
||||
}
|
||||
@ -87,6 +89,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
missing.add(i)
|
||||
}
|
||||
}
|
||||
rs.close()
|
||||
return missing
|
||||
} catch (e: SQLException) {
|
||||
e.printStackTrace()
|
||||
@ -111,16 +114,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
|
||||
}
|
||||
|
||||
fun getMessagesFromUserCount(): Int {
|
||||
try {
|
||||
val rs = stmt!!.executeQuery("SELECT COUNT(*) FROM messages WHERE sender_id=" + user_manager.user!!.getId())
|
||||
rs.next()
|
||||
return rs.getInt(1)
|
||||
} catch (e: SQLException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
|
||||
}
|
||||
fun getMessagesFromUserCount() = queryInt("SELECT COUNT(*) FROM messages WHERE sender_id=" + user_manager.user!!.getId())
|
||||
|
||||
fun getMessageTypesWithCount(): HashMap<String, Int> = getMessageTypesWithCount(GlobalChat())
|
||||
|
||||
@ -164,7 +158,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
try {
|
||||
val rs = stmt!!.executeQuery("PRAGMA encoding")
|
||||
rs.next()
|
||||
return rs.getString(1)
|
||||
val result = rs.getString(1)
|
||||
rs.close()
|
||||
return result
|
||||
} catch (e: SQLException) {
|
||||
logger.debug("SQLException: {}", e)
|
||||
return "unknown"
|
||||
@ -255,9 +251,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
|
||||
}
|
||||
|
||||
fun getTopMessageIDForChannel(id: Int): Int {
|
||||
return queryInt("SELECT MAX(message_id) FROM messages WHERE source_id=$id AND source_type IN('channel', 'supergroup')")
|
||||
}
|
||||
fun getTopMessageIDForChannel(id: Int): Int = queryInt("SELECT MAX(message_id) FROM messages WHERE source_id=$id AND source_type IN('channel', 'supergroup')")
|
||||
|
||||
fun logRun(start_id: Int, end_id: Int, count: Int) {
|
||||
try {
|
||||
@ -269,6 +263,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
ps.setInt(2, end_id)
|
||||
ps.setInt(3, count)
|
||||
ps.execute()
|
||||
ps.close()
|
||||
} catch (e: SQLException) {
|
||||
}
|
||||
|
||||
@ -278,7 +273,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
try {
|
||||
val rs = stmt!!.executeQuery(query)
|
||||
rs.next()
|
||||
return rs.getInt(1)
|
||||
val result = rs.getInt(1)
|
||||
rs.close()
|
||||
return result
|
||||
} catch (e: SQLException) {
|
||||
throw RuntimeException("Could not get count of messages.")
|
||||
}
|
||||
@ -431,6 +428,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
ps_insert_or_ignore.clearBatch()
|
||||
conn!!.commit()
|
||||
conn!!.setAutoCommit(true)
|
||||
|
||||
ps.close()
|
||||
ps_insert_or_ignore.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
throw RuntimeException("Exception shown above happened.")
|
||||
@ -486,6 +486,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
ps_insert_or_replace.clearBatch()
|
||||
conn!!.commit()
|
||||
conn!!.setAutoCommit(true)
|
||||
|
||||
ps_insert_or_ignore.close()
|
||||
ps_insert_or_replace.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
throw RuntimeException("Exception shown above happened.")
|
||||
@ -535,6 +538,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
ps_insert_or_replace.clearBatch()
|
||||
conn!!.commit()
|
||||
conn!!.setAutoCommit(true)
|
||||
|
||||
ps_insert_or_ignore.close()
|
||||
ps_insert_or_replace.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
throw RuntimeException("Exception shown above happened.")
|
||||
@ -564,6 +570,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
while (rs.next()) {
|
||||
map.put("count.messages.type." + rs.getString(1), rs.getInt(2))
|
||||
}
|
||||
rs.close()
|
||||
return map
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
@ -586,6 +593,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
map.put("count.messages.media_type.$s", rs.getInt(2))
|
||||
}
|
||||
map.put("count.messages.media_type.any", count)
|
||||
rs.close()
|
||||
return map
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
@ -625,6 +633,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
}
|
||||
map.put("authors.count.others", count_others)
|
||||
map.put("authors.all", all_data)
|
||||
rs.close()
|
||||
return map
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
@ -634,7 +643,9 @@ class Database private constructor(var client: TelegramClient) {
|
||||
fun getMessageCountForExport(c: AbstractChat): Int {
|
||||
val rs = stmt!!.executeQuery("SELECT COUNT(*) FROM messages WHERE " + c.query);
|
||||
rs.next()
|
||||
return rs.getInt(1)
|
||||
val result = rs.getInt(1)
|
||||
rs.close()
|
||||
return result
|
||||
}
|
||||
|
||||
fun getMessageTimesMatrix(c: AbstractChat): Array<IntArray> {
|
||||
@ -647,6 +658,7 @@ class Database private constructor(var client: TelegramClient) {
|
||||
while (rs.next()) {
|
||||
result[if (rs.getInt(1) == 0) 6 else rs.getInt(1) - 1][rs.getInt(2)] = rs.getInt(3)
|
||||
}
|
||||
rs.close()
|
||||
return result
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
|
@ -37,25 +37,19 @@ class DatabaseUpdates(protected var conn: Connection, protected var db: Database
|
||||
fun doUpdates() {
|
||||
try {
|
||||
val stmt = conn.createStatement()
|
||||
var rs: ResultSet
|
||||
logger.debug("DatabaseUpdate.doUpdates running")
|
||||
|
||||
logger.debug("Getting current database version")
|
||||
var version: Int
|
||||
logger.debug("Checking if table database_versions exists")
|
||||
rs = stmt.executeQuery("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='database_versions'")
|
||||
rs.next()
|
||||
if (rs.getInt(1) == 0) {
|
||||
val table_count = db.queryInt("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='database_versions'")
|
||||
if (table_count == 0) {
|
||||
logger.debug("Table does not exist")
|
||||
version = 0
|
||||
} else {
|
||||
logger.debug("Table exists. Checking max version")
|
||||
rs.close()
|
||||
rs = stmt.executeQuery("SELECT MAX(version) FROM database_versions")
|
||||
rs.next()
|
||||
version = rs.getInt(1)
|
||||
version = db.queryInt("SELECT MAX(version) FROM database_versions")
|
||||
}
|
||||
rs.close()
|
||||
logger.debug("version: {}", version)
|
||||
System.out.println("Database version: " + version)
|
||||
logger.debug("Max available database version is {}", maxPossibleVersion)
|
||||
@ -106,6 +100,9 @@ class DatabaseUpdates(protected var conn: Connection, protected var db: Database
|
||||
} catch (e: SQLException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
|
||||
println("Cleaning up the database (this might take some time)...")
|
||||
try { stmt.executeUpdate("VACUUM") } catch (t: Throwable) { logger.debug("Exception during VACUUMing: {}", t) }
|
||||
|
||||
} else {
|
||||
logger.debug("No update necessary.")
|
||||
@ -441,7 +438,5 @@ internal class DB_Update_9(conn: Connection, db: Database) : DatabaseUpdate(conn
|
||||
}
|
||||
println()
|
||||
logger.info("Converted ${i} of ${count} messages.")
|
||||
println(" Cleaning up the database (this might also take some time, sorry)...")
|
||||
execute("VACUUM")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user