Added the ability to pin and unpin toots with the pin and unpin command. Would like to clean up code as well as possibly toot confirmation and error messages
This commit is contained in:
parent
2b2824a73e
commit
011ec2c9a8
2 changed files with 28 additions and 10 deletions
5
main.py
5
main.py
|
@ -11,8 +11,9 @@ import os, sqlite3, signal, sys, json, re, shutil
|
||||||
import requests
|
import requests
|
||||||
import functions
|
import functions
|
||||||
|
|
||||||
scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses", "read:notifications"]
|
scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses", "read:notifications", "write:accounts"]
|
||||||
#cfg defaults
|
#cfg defaults
|
||||||
|
|
||||||
cfg = {
|
cfg = {
|
||||||
"site": "https://botsin.space",
|
"site": "https://botsin.space",
|
||||||
"cw": None,
|
"cw": None,
|
||||||
|
@ -21,10 +22,10 @@ cfg = {
|
||||||
"mention_handling": 1,
|
"mention_handling": 1,
|
||||||
"max_thread_length": 15
|
"max_thread_length": 15
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cfg.update(json.load(open('config.json', 'r')))
|
cfg.update(json.load(open('config.json', 'r')))
|
||||||
except:
|
except:
|
||||||
|
|
||||||
shutil.copy2("config.sample.json", "config.json")
|
shutil.copy2("config.sample.json", "config.json")
|
||||||
cfg.update(json.load(open('config.json', 'r')))
|
cfg.update(json.load(open('config.json', 'r')))
|
||||||
|
|
||||||
|
|
33
reply.py
33
reply.py
|
@ -38,6 +38,7 @@ class ReplyListener(mastodon.StreamListener):
|
||||||
posts = 0
|
posts = 0
|
||||||
for post in context['ancestors']:
|
for post in context['ancestors']:
|
||||||
if post['account']['id'] == me:
|
if post['account']['id'] == me:
|
||||||
|
pin = post["id"] #Only used if pin is called, but easier to call here
|
||||||
posts += 1
|
posts += 1
|
||||||
if posts >= cfg['max_thread_length']:
|
if posts >= cfg['max_thread_length']:
|
||||||
# stop replying
|
# stop replying
|
||||||
|
@ -45,14 +46,30 @@ class ReplyListener(mastodon.StreamListener):
|
||||||
return
|
return
|
||||||
|
|
||||||
mention = extract_toot(notification['status']['content'])
|
mention = extract_toot(notification['status']['content'])
|
||||||
toot = functions.make_toot(True)['toot'] #generate a toot
|
if (mention == "pin") or (mention == "unpin"): #check for keywords
|
||||||
toot = acct + " " + toot #prepend the @
|
print("Found pin/unpin")
|
||||||
print(acct + " says " + mention) #logging
|
#get a list of people the bot is following
|
||||||
visibility = notification['status']['visibility']
|
validusers = client.account_following(me)
|
||||||
if visibility == "public":
|
for user in validusers:
|
||||||
visibility = "unlisted"
|
if user["id"] == notification["account"]["id"]: #user is #valid
|
||||||
client.status_post(toot, post_id, visibility=visibility, spoiler_text = cfg['cw']) #send toost
|
print("User is valid")
|
||||||
print("replied with " + toot) #logging
|
if mention == "pin":
|
||||||
|
print("pin received, pinning")
|
||||||
|
client.status_pin(pin)
|
||||||
|
else:
|
||||||
|
print("unpin received, unpinning")
|
||||||
|
client.status_unpin(pin)
|
||||||
|
else:
|
||||||
|
print("User is not valid")
|
||||||
|
else:
|
||||||
|
toot = functions.make_toot(True)['toot'] #generate a toot
|
||||||
|
toot = acct + " " + toot #prepend the @
|
||||||
|
print(acct + " says " + mention) #logging
|
||||||
|
visibility = notification['status']['visibility']
|
||||||
|
if visibility == "public":
|
||||||
|
visibility = "unlisted"
|
||||||
|
client.status_post(toot, post_id, visibility=visibility, spoiler_text = cfg['cw']) #send toost
|
||||||
|
print("replied with " + toot) #logging
|
||||||
|
|
||||||
rl = ReplyListener()
|
rl = ReplyListener()
|
||||||
client.stream_user(rl) #go!
|
client.stream_user(rl) #go!
|
||||||
|
|
Loading…
Reference in a new issue