Compare commits

...

3 Commits

Author SHA1 Message Date
an ca775aff0d emacs: use json-mode 2020-08-03 23:39:32 -06:00
an ba25bd9827 emacs: fix warning 2020-08-03 23:39:20 -06:00
an 67d17c4a3f add extremely overdetailed gender script 2020-08-03 23:39:10 -06:00
3 changed files with 143 additions and 1 deletions

View File

@ -95,6 +95,9 @@
:foreground "#92ebf0"))
;; major modes
(use-package json-mode
:ensure t)
(use-package mmm-mode
:ensure t
:init
@ -119,7 +122,8 @@
:mode (("\\.zsc\\'" . c-mode)
("\\.zc\\'" . c-mode))
:init
(setq c-auto-align-backslashes nil)
(setq c-auto-align-backslashes nil
c-basic-offset tab-width)
(defvaralias 'c-basic-offset 'tab-width))
(use-package fish-mode

7
fish/gender-swap Normal file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env fish
function gender-swap -d 'Swaps gender'
"$_agw_dir_rc"/text/gender-swap $args
end
## EOF

131
text/gender-swap Executable file
View File

@ -0,0 +1,131 @@
#!/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.map.with_index do |v, k|
url_params(v, key + "[" + k.to_s + "]", output)
end
when param.is_a?(Hash)
param.map 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.pop
PRESENTATION = ARGV.pop
PRONOUNS = ARGV.pop.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