Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegram-history-cleanup
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
telegram-history-cleanup
Commits
a5e08a96
There was an error fetching the commit references. Please try again later.
Commit
a5e08a96
authored
1 year ago
by
Recolic
Browse files
Options
Downloads
Patches
Plain Diff
adjust
parent
230f6a43
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-7
4 additions, 7 deletions
README.md
tg-history-cleanup.py
+11
-8
11 additions, 8 deletions
tg-history-cleanup.py
with
15 additions
and
15 deletions
README.md
+
4
−
7
View file @
a5e08a96
# Script to delete your history message from groups
This script will automatically delete your history message in all joined groups.
It will check the latest
`n`
messages of each joined group, and delete the message if:
It will check the latest messages
(until
`n`
seconds ago)
of each joined group, and delete the message if:
1.
It was sent from you
2.
The group is not whitelisted
3.
The
group
was sent at least
`t`
seconds ago
3.
The
message
was sent at least
`t`
seconds ago
It's recommended to auto-run this script daily to protect your privacy.
这个脚本会自动从所有已加入群组删除你的历史消息.
它会检查每个已加入群组的最近
的n条
消息, 并且在满足以下条件时删除它:
它会检查每个已加入群组的最近
n秒钟的所有
消息, 并且在满足以下条件时删除它:
1.
消息是你发的
2.
这个群组不在白名单里
3.
这个消息
是一定时间段前发的
3.
这个消息
已经过去t秒了
我们建议你每天自动运行一次此脚本, 来保护你的隐私.
...
...
@@ -30,7 +30,4 @@ The configuration options might be different but you should be able to figure it
具体配置项目可能有所不同, 但你应该足够聪明可以理解.
## TODO
Use timestamp instead of
`MSG_DOWNLOAD_LIMIT`
as terminal condition
This diff is collapsed.
Click to expand it.
tg-history-cleanup.py
+
11
−
8
View file @
a5e08a96
#!/usr/bin/python3 -u
# This script will automatically delete your history message in all joined groups.
# It will check the latest
`n`
messages of each joined group, and delete the message if:
# It will check the latest messages
(until `n` seconds ago)
of each joined group, and delete the message if:
# 1. It was sent from you
# 2. The group is not whitelisted in (WHITELIST_CHATS)
# 3. The group was sent at least `t` seconds ago
...
...
@@ -15,7 +15,7 @@ TELEGRAM_API_HASH = '67e72cc9e2b603e08d05446ad5ef8e6'
TELEGRAM_PHONE
=
'
+12223334444
'
# Phone number in International Format. Example: '+8617719890604'
WHITELIST_CHATS
=
[
'
-692222222
'
,
'
-100195111111111
'
]
MSG_DOWNLOAD_LIMIT
=
10000
#
Set to '0' for dry-run, set to a huge number for first-run.
MSG_DOWNLOAD_
TIME_
LIMIT
=
4
*
24
*
60
*
60
# 4 days ago.
Set to '0' for dry-run, set to a huge number for first-run.
MSG_ALIVE_TIME
=
24
*
60
*
60
# 1 day
##################### Configuration End ########################
...
...
@@ -34,7 +34,7 @@ def result_of(async_result):
async_result
.
wait
()
return
async_result
.
update
def
delete_all_msg_from_me
(
telegram
,
group_id
,
receiv
e_limit
,
my_userid
):
def
delete_all_msg_from_me
(
telegram
,
group_id
,
pull_tim
e_limit
,
my_userid
):
receive
=
True
from_message_id
=
0
stats_data
=
{}
...
...
@@ -51,11 +51,14 @@ def delete_all_msg_from_me(telegram, group_id, receive_limit, my_userid):
msg_to_delete
=
[]
for
message
in
response
.
update
[
'
messages
'
]:
if
message
[
'
date
'
]
<
current_timestamp
-
pull_time_limit
:
receive
=
False
break
if
message
[
'
sender_id
'
][
'
@type
'
]
!=
'
messageSenderUser
'
:
# Not sent from user. Ignore it.
from_message_id
=
message
[
'
id
'
]
continue
if
message
[
'
sender_id
'
][
'
user_id
'
]
==
my_userid
and
message
[
'
date
'
]
<
current_timestamp
-
24
*
60
*
60
:
if
message
[
'
sender_id
'
][
'
user_id
'
]
==
my_userid
and
message
[
'
date
'
]
<
current_timestamp
-
MSG_ALIVE_TIME
:
msg_to_delete
.
append
(
message
[
'
id
'
])
else
:
from_message_id
=
message
[
'
id
'
]
...
...
@@ -64,11 +67,11 @@ def delete_all_msg_from_me(telegram, group_id, receive_limit, my_userid):
print
(
"
DEBUG: delete msg count=
"
,
len
(
msg_to_delete
))
tg
.
delete_messages
(
group_id
,
msg_to_delete
)
processed_msg_count
+=
len
(
response
.
update
[
'
messages
'
])
if
processed_msg_count
>
receive_limit
or
not
response
.
update
[
'
total_count
'
]:
if
not
response
.
update
[
'
total_count
'
]:
receive
=
False
print
(
f
'
[
{
processed_msg_count
}
/
{
receive_limit
}
] processed
'
)
processed_msg_count
+=
len
(
response
.
update
[
'
messages
'
])
print
(
f
'
[
{
processed_msg_count
}
] processed
'
)
if
__name__
==
'
__main__
'
:
...
...
@@ -85,7 +88,7 @@ if __name__ == '__main__':
continue
group_title
=
result_of
(
tg
.
get_chat
(
chatid
))[
'
title
'
]
print
(
"
Will cleaning up chat_id
"
,
chatid
,
group_title
)
delete_all_msg_from_me
(
tg
,
str
(
chatid
),
MSG_DOWNLOAD_LIMIT
,
my_id
)
delete_all_msg_from_me
(
tg
,
str
(
chatid
),
MSG_DOWNLOAD_
TIME_
LIMIT
,
my_id
)
tg
.
stop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment