A work-in-progress chat bot for Streamplace with chat overlay functionality
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

!song command

+60 -5
+60 -5
utils/commands/defaultCommands.ts
··· 92 92 }; 93 93 94 94 const linkatCommand: CommandHandler = async (_message, _args, bot) => { 95 - const streamer = await bot.getUserProfile(bot.getStreamerDid()); 95 + const streamerDid = bot.getStreamerDid(); 96 + const streamer = await bot.getUserProfile(streamerDid); 96 97 const linkat = await getRecord(streamer.pdsEndpoint, { 97 - repo: bot.getStreamerDid(), 98 + repo: streamerDid, 98 99 collection: "blue.linkat.board", 99 100 rkey: "self", 100 101 }); 101 102 if (!linkat) { 102 103 const { text, facets } = new RichtextBuilder() 103 - .addText( 104 - "This user has no Linkat board. You can create one at ", 105 - ) 104 + .addMention(streamer.handle, streamerDid) 105 + .addText(" has no Linkat board. You can create one at ") 106 106 .addLink("https://linkat.blue/", "https://linkat.blue/") 107 107 .addText("!"); 108 108 ··· 179 179 await bot.sendMessage(text, facets); 180 180 }; 181 181 182 + const songCommand: CommandHandler = async (_message, _args, bot) => { 183 + const streamerDid = bot.getStreamerDid(); 184 + const streamer = await bot.getUserProfile(streamerDid); 185 + const tealStatus = await getRecord(streamer.pdsEndpoint, { 186 + repo: streamerDid, 187 + collection: "fm.teal.alpha.actor.status", 188 + rkey: "self", 189 + }); 190 + if (!tealStatus) { 191 + const { text, facets } = new RichtextBuilder() 192 + .addMention(streamer.handle, streamerDid) 193 + .addText(" is not using ") 194 + .addLink("teal.fm", "https://teal.fm/") 195 + .addText(" for scrobbling!"); 196 + 197 + await bot.sendMessage(text, facets); 198 + return; 199 + } 200 + 201 + const tealItem = tealStatus.value.item as { 202 + artists?: Array<{ artistName: string }>; 203 + originUrl?: `${string}:${string}`; 204 + trackName?: string; 205 + releaseName?: string; 206 + }; 207 + if (!tealItem.trackName || tealItem.trackName === "") { 208 + const { text, facets } = new RichtextBuilder() 209 + .addText("No song detected as currently playing!"); 210 + 211 + await bot.sendMessage(text, facets); 212 + return; 213 + } 214 + 215 + const richtextBuilder = new RichtextBuilder() 216 + .addText("Currently playing: "); 217 + if (tealItem.originUrl) { 218 + richtextBuilder.addLink(tealItem.trackName, tealItem.originUrl); 219 + } else { 220 + richtextBuilder.addText(tealItem.trackName); 221 + } 222 + if (tealItem.artists) { 223 + richtextBuilder.addText(" by "); 224 + tealItem.artists.forEach((artist, index) => { 225 + richtextBuilder.addText(artist.artistName); 226 + if (index < tealItem.artists!.length - 1) { 227 + richtextBuilder.addText(", "); 228 + } 229 + }); 230 + } 231 + 232 + const { text, facets } = richtextBuilder; 233 + await bot.sendMessage(text, facets); 234 + }; 235 + 182 236 export const defaultCommands: Map<string, CommandHandler> = new Map([ 183 237 ["commands", commandsCommand], 184 238 ["shoutout", shoutoutCommand], 185 239 ["so", shoutoutCommand], 186 240 ["hug", hugCommand], 241 + ["song", songCommand], 187 242 ["linkat", linkatCommand], 188 243 ["pronouns", pronounsCommand], 189 244 ["lurk", lurkCommand],