<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://ulysseszh.github.io/feed/tags/android.xml" rel="self" type="application/atom+xml" /><link href="https://ulysseszh.github.io/" rel="alternate" type="text/html" hreflang="en-US" /><updated>2026-04-19T16:48:01-07:00</updated><id>https://ulysseszh.github.io/feed/tags/android.xml</id><title type="html"><![CDATA[Ulysses’ trip]]></title><subtitle>Here we are at the awesome (awful) blog written by UlyssesZhan!</subtitle><author><name>UlyssesZhan</name><email>ulysseszhan@gmail.com</email></author><entry><title type="html"><![CDATA[Letting people know when you are asleep]]></title><link href="https://ulysseszh.github.io/guide/2024/02/21/sleep-status.html" rel="alternate" type="text/html" title="Letting people know when you are asleep" /><published>2024-02-21T02:26:45-08:00</published><updated>2024-02-21T02:26:45-08:00</updated><id>https://ulysseszh.github.io/guide/2024/02/21/sleep-status</id><content type="html" xml:base="https://ulysseszh.github.io/guide/2024/02/21/sleep-status.html"><![CDATA[<p>While I have been trying to respond whenever people reach out to me, it is impossible to be available 24/7 due to the simple fact that <a href="https://www.sleepfoundation.org/how-sleep-works/why-do-we-need-sleep" target="_blank" rel="external">a human has to sleep to be alive</a>. While this is annoying, it is also a fact that I cannot change.</p>
<p>Therefore, a natural idea that comes to my mind is to simply let people know when I am asleep so that they do not expect me to respond immediately.</p>
<p>Discord and GitHub have been among my most used platforms for some time, and they both have a feature to let users set a custom status (with a custom text and an emoji). This opens up a possibility of using a program to automatically set the status to indicate that I am asleep.</p>
<p>For Discord, this is as simple as invoking a REST API (<a href="https://support.discord.com/hc/en-us/articles/115002192352-Automated-user-accounts-self-bots" target="_blank" rel="external"><strong>Notice that this is against Discord’s ToS</strong></a>):</p>
<table class="rouge-table">
  <tbody>
    <tr>
      <td class="highlight language-shell">
        <pre>
          <code>
            <span class="line line-1"><span class="c"># Set sleeping status</span>
</span>
            <span class="line line-2">curl <span class="nt">-X</span> PATCH <span class="se">\</span>
</span>
            <span class="line line-3">	<span class="nt">-H</span> <span class="s2">"Content-Type: application/json"</span> <span class="se">\</span>
</span>
            <span class="line line-4">	<span class="nt">-H</span> <span class="s2">"Authorization: YoUr.DiScOrD.ToKeN"</span> <span class="se">\</span>
</span>
            <span class="line line-5">	<span class="nt">-d</span> <span class="s1">'{"settings":"WhwKBQoDZG5kEhMKC1NsZWVwaW5nLi4uGgTwn5i0"}'</span> <span class="se">\</span>
</span>
            <span class="line line-6">	https://discord.com/api/v9/users/@me/settings-proto/1
</span>
            <span class="line line-7">
</span>
            <span class="line line-8">
</span>
            <span class="line line-9"><span class="c"># Clear sleeping status</span>
</span>
            <span class="line line-10">curl <span class="nt">-X</span> PATCH <span class="se">\</span>
</span>
            <span class="line line-11">	<span class="nt">-H</span> <span class="s2">"Content-Type: application/json"</span> <span class="se">\</span>
</span>
            <span class="line line-12">	<span class="nt">-H</span> <span class="s2">"Authorization: YoUr.DiScOrD.ToKeN"</span> <span class="se">\</span>
</span>
            <span class="line line-13">	<span class="nt">-d</span> <span class="s1">'{"settings":"WgoKCAoGb25saW5l"}'</span> <span class="se">\</span>
</span>
            <span class="line line-14">	https://discord.com/api/v9/users/@me/settings-proto/1
</span>
          </code>
        </pre>
      </td>
    </tr>
  </tbody>
</table>
<p>If you wonder what those base64-encoded strings mean, they are actually the binary contents of protobuf-encoded messages. See <a href="https://github.com/discord-userdoccers/discord-protos/blob/master/discord_protos/discord_users/v1/PreloadedUserSettings.proto" target="_blank" rel="external">this <code>.proto</code> file</a> for the definition of the message structure.</p>
<details>
<summary>
API v8
</summary>
<p>The commands written above was added when editing this article on July 20, 2025, which uses API v9. The latest API version as of originally writing this article was v8, but now <strong>using API v8 will get your account disabled</strong>, so do not use it!</p>
<table class="rouge-table"><tbody><tr><td class="highlight language-shell"><pre><code><span class="line line-1"><span class="c"># Set sleeping status</span>
</span><span class="line line-2">curl <span class="nt">-X</span> PATCH <span class="se">\</span>
</span><span class="line line-3">	<span class="nt">-H</span> <span class="s2">"Content-Type: application/json"</span> <span class="se">\</span>
</span><span class="line line-4">	<span class="nt">-H</span> <span class="s2">"Authorization: YoUr.DiScOrD.ToKeN"</span> <span class="se">\</span>
</span><span class="line line-5">	<span class="nt">-d</span> <span class="s1">'{"custom_status":{"text":"Sleeping...","emoji_id":null,"emoji_name":"😴","expires_at":null},"status":"dnd"}'</span> <span class="se">\</span>
</span><span class="line line-6">	https://discordapp.com/api/v8/users/@me/settings
</span><span class="line line-7">
</span><span class="line line-8"><span class="c"># Clear sleeping status</span>
</span><span class="line line-9">curl <span class="nt">-X</span> PATCH <span class="se">\</span>
</span><span class="line line-10">	<span class="nt">-H</span> <span class="s2">"Content-Type: application/json"</span> <span class="se">\</span>
</span><span class="line line-11">	<span class="nt">-H</span> <span class="s2">"Authorization: YoUr.DiScOrD.ToKeN"</span> <span class="se">\</span>
</span><span class="line line-12">	<span class="nt">-d</span> <span class="s1">'{"custom_status":null,"status":"online"}'</span> <span class="se">\</span>
</span><span class="line line-13">	https://discordapp.com/api/v8/users/@me/settings
</span></code></pre></td></tr></tbody></table>
</details>
<p>For GitHub, <a href="https://github.com/orgs/community/discussions/108473" target="_blank" rel="external">there is not a REST API for that</a>, but you can install the <a href="https://github.com/vilmibm/gh-user-status" target="_blank" rel="external">user-status plugin</a> for <a href="https://cli.github.com/" target="_blank" rel="external">GitHub CLI</a>:</p>
<table class="rouge-table">
  <tbody>
    <tr>
      <td class="highlight language-shell">
        <pre>
          <code>
            <span class="line line-1">gh extension <span class="nb">install </span>vilmibm/gh-user-status
</span>
          </code>
        </pre>
      </td>
    </tr>
  </tbody>
</table>
<p class="no-indent">
Then, you can set the status with:
</p>
<table class="rouge-table">
  <tbody>
    <tr>
      <td class="highlight language-shell">
        <pre>
          <code>
            <span class="line line-1"><span class="c"># Set sleeping status</span>
</span>
            <span class="line line-2">gh user-status <span class="nb">set</span> <span class="s1">'Sleeping...'</span> <span class="nt">--emoji</span><span class="o">=</span><span class="s1">'sleeping'</span> <span class="nt">--limited</span>
</span>
            <span class="line line-3">
</span>
            <span class="line line-4"><span class="c"># Clear sleeping status</span>
</span>
            <span class="line line-5">gh user-status <span class="nb">set</span> <span class="s1">'null'</span> <span class="nt">--expiry</span><span class="o">=</span>1s
</span>
          </code>
        </pre>
      </td>
    </tr>
  </tbody>
</table>
<p>Now, the next step is to run these commands automatically when I fall asleep and wake up. This can be done with <a href="https://www.macrodroid.com/" target="_blank" rel="external">MacroDroid</a>, which can trigger actions based on various triggers. To run arbitrary commands, you can use <a href="https://f-droid.org/en/packages/com.termux.tasker/" target="_blank" rel="external">the Tasker plugin for Termux</a>. To have it working, one also needs to uncomment <code>allow-external-apps = true</code> in <code>~/.termux/termux.properties</code>, and grant MacroDroid the permission to run Termux commands by</p>
<table class="rouge-table">
  <tbody>
    <tr>
      <td class="highlight language-shell">
        <pre>
          <code>
            <span class="line line-1">adb shell pm grant com.arlosoft.macrodroid com.termux.permission.RUN_COMMAND
</span>
          </code>
        </pre>
      </td>
    </tr>
  </tbody>
</table>
<p>MacroDroid supports using the return value of <a href="https://developers.google.com/location-context/sleep" target="_blank" rel="external">the sleep API</a> to trigger an action, but this tends to be quite unreliable on my device. Therefore, I use it in conjunction with a quick setting tile that I can toggle manually. The macro has two triggers:</p>
<ul>
<li>Fell Asleep / Woke Up (Android sleep API),</li>
<li>Quick Tile On/Off,</li>
</ul>
<p class="no-indent">
and it has these actions:
</p>
<table class="rouge-table">
  <tbody>
    <tr>
      <td class="highlight language-plain">
        <pre>
          <code>
            <span class="line line-1">If Trigger Fired: Woke Up, or Quick Tile Off
</span>
            <span class="line line-2">	If Sleeping = True
</span>
            <span class="line line-3">		Clear sleeping status on Discord and GitHub
</span>
            <span class="line line-4">		# Include other waking up logic here, such as turning off DND mode
</span>
            <span class="line line-5">	End If
</span>
            <span class="line line-6">	Sleeping = False
</span>
            <span class="line line-7">Else If Trigger Fired: Fell Asleep, or Quick Tile On
</span>
            <span class="line line-8">	If Sleeping = False
</span>
            <span class="line line-9">		Set GitHub and Discord user status to sleeping
</span>
            <span class="line line-10">		# Include other falling asleep logic here, such as turning on DND mode
</span>
            <span class="line line-11">	End If
</span>
            <span class="line line-12">	Sleeping = True
</span>
            <span class="line line-13">End If
</span>
          </code>
        </pre>
      </td>
    </tr>
  </tbody>
</table>
<p>By the way, I have a bunch of topics that I want to write blog articles about, but I have been quite busy recently, so I may have to pause updating this blog for a while. I hope I can get back to writing soon!</p>]]></content><author><name>UlyssesZhan</name><email>ulysseszhan@gmail.com</email></author><category term="guide" /><category term="android" /><category term="github" /><summary type="html"><![CDATA[While I am asleep, the sleeping state is indicated on my Discord and GitHub user status. I achieve this by using MacroDroid.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://ulysseszh.github.io/assets/images/covers/2024-02-21-sleep-status.png" /><media:content medium="image" url="https://ulysseszh.github.io/assets/images/covers/2024-02-21-sleep-status.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>