132 lines
3.2 KiB
Ruby
Executable File
132 lines
3.2 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'erb'
|
|
require 'net/http'
|
|
require 'uri'
|
|
require 'json'
|
|
require 'cgi'
|
|
|
|
# Flattens any data structure to URL parameters, recursively. Because
|
|
# apparently the standard library just doesn't fucking provide this.
|
|
# Oh well. At least it isn't something as simple as *recursively
|
|
# copying an array* (looking at you Lua.)
|
|
def url_params param, key, output = {}
|
|
case
|
|
when param.is_a?(Array)
|
|
param.each.with_index do |v, k|
|
|
url_params(v, key + "[" + k.to_s + "]", output)
|
|
end
|
|
when param.is_a?(Hash)
|
|
param.each do |k, v|
|
|
url_params(v, key + "[" + k.to_s + "]", output)
|
|
end
|
|
else
|
|
output[key] = CGI.unescapeHTML param.to_s.gsub /<\/?[^>]*>/, ""
|
|
end
|
|
output
|
|
end
|
|
|
|
CLIENT_KEY = ENV["_agw_secret_gender_swap_client_key"]
|
|
CLIENT_SECRET = ENV["_agw_secret_gender_swap_client_secret"]
|
|
ACCESS_TOKEN = ENV["_agw_secret_gender_swap_access_token"]
|
|
|
|
ALIGNMENT = ARGV[2]
|
|
PRESENTATION = ARGV[1]
|
|
PRONOUNS = ARGV[0].split("/").map do |pro|
|
|
path = if pro == "they" then "they/.../themself" else pro end
|
|
%(<a href="http://pronoun.is/#{path}">#{pro}</a>)
|
|
end
|
|
|
|
Net::HTTP.start("social.greyserv.net", use_ssl: true) do |http|
|
|
auth = {
|
|
"Authorization" => "Bearer " + ACCESS_TOKEN,
|
|
}
|
|
status = <<_end_
|
|
pronouns: #{PRONOUNS.join "/"}
|
|
presentation: #{PRESENTATION}
|
|
alignment: #{ALIGNMENT}
|
|
_end_
|
|
fields = http.get(
|
|
"/api/v1/accounts/verify_credentials",
|
|
auth,
|
|
).body
|
|
fields = JSON.parse(fields)["fields"].map do |field|
|
|
if field["name"] == "current pronouns"
|
|
field["value"] = PRONOUNS.join "/"
|
|
end
|
|
field.delete "verified_at"
|
|
field
|
|
end
|
|
http.patch(
|
|
"/api/v1/accounts/update_credentials",
|
|
URI.encode_www_form(url_params(fields, "fields_attributes")),
|
|
auth,
|
|
)
|
|
http.post(
|
|
"/api/v1/statuses",
|
|
URI.encode_www_form(
|
|
"status" => status,
|
|
"in_reply_to_id" => "104612572584164654",
|
|
"spoiler_text" => "current gender",
|
|
"visibility" => "unlisted",
|
|
"language" => "en"
|
|
),
|
|
auth,
|
|
)
|
|
end
|
|
|
|
template = ERB.new <<html
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
|
|
<link rel="stylesheet" type="text/css" href="/main.css"/>
|
|
<title>Gender</title>
|
|
</head>
|
|
|
|
<body>
|
|
<h3 class="t-center">Current</h3>
|
|
<table class="m-center">
|
|
<tr>
|
|
<td>Pronouns</td>
|
|
<td>
|
|
<ul>
|
|
<% PRONOUNS.each do |pro| %>
|
|
<li><%= pro %></li>
|
|
<% end %>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Presentation</td>
|
|
<td><%= PRESENTATION %></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Alignment</td>
|
|
<td><%= ALIGNMENT %></td>
|
|
</tr>
|
|
</table>
|
|
<h3 class="t-center">Explanation</h3>
|
|
<p>I am <a
|
|
href="https://nonbinary.wiki/wiki/Genderflux">genderflux</a>,
|
|
and my gender identity changes often. The information on this
|
|
page will be up to date with my Mastodon account, so please
|
|
check either of them if you're wondering how to most correctly
|
|
address me at a given time! Please note that it is always fine
|
|
to use <a
|
|
href="https://pronoun.is/they/.../themself">they/them</a> for
|
|
me, and I don't usually mind if pronouns other than what I'm
|
|
currently using are used.</p>
|
|
</body>
|
|
</html>
|
|
html
|
|
|
|
Net::HTTP.post(
|
|
URI("https://fuck.greyserv.net/gender.cgi"),
|
|
template.result,
|
|
"Content-Type" => "text/html",
|
|
)
|
|
|
|
# EOF
|