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 human has to sleep to be alive. While this is annoying, it is also a fact that I cannot change.

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.

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.

For Discord, this is as simple as invoking a REST API (Notice that this is against Discord’s ToS):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Set sleeping status
curl -X PATCH \
	-H "Content-Type: application/json" \
	-H "Authorization: YoUr.DiScOrD.ToKeN" \
	-d '{"custom_status":{"text":"Sleeping...","emoji_id":null,"emoji_name":"đŸ˜´","expires_at":null},"status":"dnd"}' \
	https://discordapp.com/api/v8/users/@me/settings


# Clear sleeping status
curl -X PATCH \
	-H "Content-Type: application/json" \
	-H "Authorization: YoUr.DiScOrD.ToKeN" \
	-d '{"custom_status":null,"status":"online"}' \
	https://discordapp.com/api/v8/users/@me/settings

For GitHub, there is not a REST API for that, but you can install the user-status plugin for GitHub CLI:

1
gh extension install vilmibm/gh-user-status

Then, you can set the status with:

1
2
3
4
5
# Set sleeping status
gh user-status set 'Sleeping...' --emoji='sleeping' --limited

# Clear sleeping status
gh user-status set 'null' --expiry=1s

Now, the next step is to run these commands automatically when I fall asleep and wake up. This can be done with MacroDroid, which can trigger actions based on various triggers. To run arbitrary commands, you can use the Tasker plugin for Termux. MacroDroid supports using the return value of the sleep API 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:

  • Fell Asleep / Woke Up (Android sleep API),
  • Quick Tile On/Off,

and it has these actions:

1
2
3
4
5
6
7
8
9
10
11
12
13
If Trigger Fired: Woke Up, or Quick Tile Off
	If Sleeping = True
		Clear sleeping status on Discord and GitHub
		# Include other waking up logic here, such as turning off DND mode
	End If
	Sleeping = False
Else If Trigger Fired: Fell Asleep, or Quick Tile On
	If Sleeping = False
		Set GitHub and Discord user status to sleeping
		# Include other falling asleep logic here, such as turning on DND mode
	End If
	Sleeping = True
End If

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!