previndexinfo

code guessing, round #74, stage 2 (guessing)

started at ; stage 2 since . guess by

specification

sorry I'm late, I overslept. uh, please send a song in discord. submissions may be written in languages with support for networking.

the API endpoint Create Message (POST https://discord.com/api/v10/channels/{channel.id}/messages) allows bot accounts to send messages on Discord. you'll need these headers for your request to go through:

User-Agent: DiscordBot (https://github.com/ClientLibraryMakers/MyClientLibrary, 1.0.0)
Content-Type: application/json
Authorization: Bot MTk4NjIyNDgzNDcxOTI1MjQ4.Cl2FMQ.ZnCjm1XVW7vRze4b7Cq4se7kKWs

you can use the content field in the body to include a link to a song ({"content": "https://soundcloud.com/100gecs/757a1"}). if you would like to send it as an attachment, the request should be a multipart/form-data request including a files[0] file:

...
Content-Type: multipart/form-data; boundary=mjauuuu

--mjauuuu
Content-Disposition: form-data; name="content"

here is your song I made it for you
--mjauuuu
Content-Disposition: form-data; name="files[0]"; filename="yoursong.ogg"
Content-Type: audio/ogg

[audio bytes]
--mjauuuu--

if you like, you can send the rest of the request as ordinary JSON while doing this using a key named payload_json:

...
Content-Type: multipart/form-data; boundary=mjauuuu

--mjauuuu
Content-Disposition: form-data; name="payload_json"
Content-Type: application/json

{
  "embeds": [{
    "title": "wow!",
    "description": "look at this song I made for you :heart:"
  }]
}
--mjauuuu
Content-Disposition: form-data; name="files[0]"; filename="yoursong.ogg"
Content-Type: audio/ogg

[audio bytes]
--mjauuuu--

your challenge, given a bot token and the ID of a channel it can send to, is to send a song to that channel. as most languages are allowed, and the prompt is somewhat open-ended, there is no fixed API.

players

  1. LyricLy
  2. Makefile_dot_in
  3. oleander
  4. taswelll
  5. yeti

entries

you can download all the entries

entry #1

comments 0

post a comment


bot.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
channel = int(input())

import discord
client = discord.Client(intents=discord.Intents.default())

@client.event
async def on_ready():
    await client.get_channel(channel).send("https://weatherornot.bandcamp.com/track/blanket")

client.run(input())

entry #2

comments 0

post a comment


cg73.tcl ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package require http
package require tls

http::register https 443 ::tls::socket
http::config -useragent {DiscordBot (https://codeguessing.gay, 1.0.0) songebot/1.0 (zzz)}

set song_list {
    https://www.youtube.com/watch?v=T5Cp55MvX54
    https://www.youtube.com/watch?v=eA2kiCScnI8&t=56s
    https://www.youtube.com/watch?v=vW9_5giCK1I
    https://www.youtube.com/watch?v=nXZuv1T8bfg
    https://www.youtube.com/watch?v=Lt-EbHhHD5Q
}

proc send {token channel_id} {
    set song [lindex $::song_list [expr {round(floor([llength $::song_list] * rand()))}]]
    set token [http::geturl https://discord.com/api/v10/channels/$channel_id/messages \
        -method POST \
        -query [subst {{"content": "$song"}}] \
        -headers [dict create \
                      content-type application/json \
                      authorization "Bot $token"
                 ]]

    set ret [http::data $token]
    http::cleanup $token
    set ret
}

array set arguments $argv
puts [send $arguments(-token) $arguments(-channel-id)]

# Then it waddled away...
# Waddle waddle

entry #3

comments 0

post a comment


diner.mp3 Audio file with ID3 version 2.47.42, contains: MPEG ADTS, layer III, v1, 64 kbps, 44.1 kHz, Stereo

entry #4

comments 0

post a comment


The Most Wanted Person In The United States.mp3 Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 64 kbps, 44.1 kHz, Stereo
bot74.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import requests

t='bottoken'
c='channelid'
n='The Most Wanted Person In The United States.mp3'
f=open(n,'rb')

h={'authorization' :'Bot '+t}
s=os.path.getsize(n)
u='https://discord.com/api/v10/channels/'+str(c)+'/messages'

a='https://discord.com/api/v10/channels/'+str(c)+'/attachments'
l={"files":[{"filename":n,"file_size":s,"id":"0"}]}
r=requests.post(a,headers=h,json=l)

o=r.json()['attachments'][0]['upload_url']
m=r.json()['attachments'][0]['upload_filename']
d={'Content-Length':str(s),'Connection':'keep-alive','Content-Type':'audio/mp3','authorization' :'Bot '+t}
p=requests.put(o,headers=d,data=f)    

i={"attachments":[{"id":"0","filename":n,"uploaded_filename":m}]}
p=requests.post(u,headers=h,json=i)
f.close()

entry #5

comments 0

post a comment


main.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This example requires the 'message_content' intent.

import discord

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f'We have logged in as {client.user}')

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith("$song"):
        await message.channel.send("https://www.youtube.com/watch?v=dsuJZx24V_A")

client.run("NzUyOTI0MTA5ODk3MjAzODcz.GlP4tR.9HigYa2kwGXaLaW06ngZKpklVdb6mHT55ng2is")