-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.lua
59 lines (46 loc) · 1.35 KB
/
example.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local lfs = require("lfs")
local mastodon = require("mastodon")
-- change this to the apprpriate instance, login and username
local instance_url = "https://mastodon.social"
local user_name = "[email protected]"
local user_password = "example123"
if lfs.attributes("secrets.lua") then
dofile("secrets.lua")
instance_url, user_name, user_password = get_secrets()
end
if not lfs.attributes("clientcred.txt") then
print("No client credentials locally stored yet.")
print("Will try to register app in server...")
local id, err = mastodon.create_app {
client_name = "Lua Test",
scopes= { "read", "write" },
to_file = "clientcred.txt",
api_base_url = instance_url
}
if id then
print("Successfully registered app - got ID " .. id)
else
print("Failed registering app in server :( - error: " .. err)
os.exit(1)
end
end
local mclient = mastodon.new {
client_id = "clientcred.txt",
api_base_url = instance_url
}
print("Logging in...")
local access, err = mclient:log_in {
username = user_name,
password = user_password,
scopes = { "read", "write" },
to_file = "usercred.txt"
}
if not access then
print("Login failed :( - error: " .. err)
os.exit(1)
end
print("Logged in! :)")
local toot = arg[1] or "Toot toot from Lua!"
print("Tooting!...")
local result = mclient:toot(toot)
os.exit(0)