Miscellaneous

Not all connections are created equal - although most are fairly complicated, a few are compiled onto this page because they’re simple enough to not need a whole page of their own.


Discord Connection

Sinoper uses this class to connect to Discord as a bot user. Once fully implemented, it will facilitate “conversation” and command input from users and servers there. Message events received here should be passed up to the Core for parsing, but Sinoper currently only has a very simple placeholder handler (shown below).

client.on('messageCreate', async message => {
	if (
		// filter out messages from servers which aren't my testing server
		message.guildId !== GuildID ||

		// filter out messages from itself
		message.author.id === ClientID
	) {
		return
	}

	console.log(message.content)

	// a bird-themed 'pong' reply
	message.channel.send('chirp :V')
})

MIDI Connection

This connection serves to allow my MIDI piano to function as a makeshift stream deck - a control surface separate from the keyboard which automates various tasks. Some of such use cases include quickly put up polls in chat, using a preset group of stream settings for different games, and controlling the volume of the music. The first two can be done using keyboard hotkeys but could take up over a dozen key combinations, and the second wants an analog wheel. With piano keys and MIDI sliders at my disposal, these tasks become easy.

That said, the implementation of the connection itself is a very simple wrapper for node-midi’s Input class, and its entirety is shown below. Handling of commands generated by MIDI events is, of course, taken care of by the Core.

import { Input } from 'midi'

export class SinoperMidi extends Input {
	constructor() {
		super()

		this.openPort(0)
		this.ignoreTypes(false, true, true)
	}
}

Spotify Connection

This connection is not implemented yet, but it’s how Sinoper is going to interact with the stream’s background music. I stream music from Spotify and like to display the currently playing track on the overlay, and I also like to be able to easily adjust the volume during the stream for a number of reasons. To facilitate this, this connection will regularly query Spotify to get the current song and generate events to pass up to the Core, and have methods to handle the boilerplate for calls to set the volume and such.

6/26/2022