Fix R code or translate simple Python function to R
$10-30 USD
Plačilo ob prevzemu
I am developing an R code that uses a web-socket to send messages as they arrive from Discord to R (not to be confuse with having R querying Discord constantly for new messages).
Rather than having R asking Discord every certain amount of time for new messages (so you know, Discord does not allows this; Discord has a limit of how many times you can request messages), the websocket allows for Discord to send messages to R only when the arrive.
Python has a well-developed package called [login to view URL] that does this operation flawlessly (Tutorial here: [login to view URL]); working code below.
In R there are two libraries (websocket and httpuv) that do this, but the code I developed while working, closes the connection after some random amount of time from a few minutes to hours (I think Python has a safety reconnecting code, yet to be implemented in R, but not sure). The errors have different names like: "Unhandled promise error: invalid state", etc.
I found that [login to view URL] has numerous functions to deal with the discord gateway connectivity:
[login to view URL]
The job at hand is to fix the existing R code (Provided below) so it run non-stop, or translate the Python function to an R function (I need the actual code in R, not just connecting from R to Python like via reticulate package).
All codes I have are below. This could be as simple as adding a line of code I am missing, or creating a safety check to re-start connectivity upon disconnection, or a re-doing the python code in R.
Working Python code:
---------------------------------------------------------------
import discord
intents= [login to view URL]()
intents.message_content = True
client = [login to view URL]( intents=intents)
@[login to view URL]
async def on_message(message):
print([login to view URL])
[login to view URL]("BotToken")
--------------------------------------------------------------------
The R code:
------------------------------------------------------
library(websocket)
library(jsonlite)
library(async)
Heartbeat =10 #container for heartbite
DiscordSignals <- function(DiscordToken){
#payloads or messages that R has to send to Discord.
Rpayload = list(
op= 2,
d= list(
token= DiscordToken,
intents= 513,
properties=list(
os= "windows",
browser= "firefox",
device= "firefox")
)
)
KeepAlive = list(op= 1, d= "null" )
Jsonpayload = toJSON(Rpayload, auto_unbox = TRUE, pretty = TRUE)
JsonKeepAlive = toJSON(KeepAlive, auto_unbox = TRUE, pretty = TRUE)
ws <<- WebSocket$new("wss://[login to view URL]", errorLogChannels ="warn")
ws$onOpen(function(event) {ws$send(Jsonpayload)}) #Handshake
ws$onMessage(function(event) {
d <- event$data
json = fromJSON(d)
Alert= json$d$content
OP<<[login to view URL](json$op) #Type of message sent from Discord
#[login to view URL]
#Discord may request additional heartbeats from your app by sending a Heartbeat (opcode OP1) event. Upon receiving the event, .. immediately send back .. Heartbeat ...
#reset heartbeat rate to whatever asked by Discord. Heartbite rate send from Discord in OPs 1 or 10.
if (OP %in% c(1,10)){Heartbeat <<-round(abs(((json$d$heartbeat_interval )/1000)-runif(1)-3),0)}
print (Alert)
})
#send heartbeat every given interval
async({
p=1
while (p==1){
await(delay(Heartbeat))
ws$send(JsonKeepAlive)
}
})
}
DiscordSignals (BotToken)
ID projekta: #37170793
Več o projektu
13 freelancerjev ponuja v povprečju za $44 na tem delu
Top 1% in Freelancer.com Hi, Greetings! ✅checked your project details: ✅Completed Time: In project deadline We have worked on 900 + Projects. I have 6 + years of the experience in same kind of projects. If you are look Več
Hey there, Glane here i can help in fixing the existing R code without errors. Feel free to get in touch.
Hello there! My name is Mosammet Farjana Akther and I am a professional website and mobile app developer. I understand that you are looking for someone to help you with the task of fixing your R code or translating th Več
Hello. I read your requirement i will fix that. Please come on chat we will discuss more about this. I will waiting your reply.
Hello, I read through, and I can help. I am proficient in both programming languages, and I understand the problem you are to solve. Kindly text me over the chats we discuss further. Thank you
Hi there, I can do your project. I know R studio well, I use R markdown or R files. I can code about data. I know Python too
Hi! I am interested in your project Fix R code or translate simple Python function to R I have completed similar papers in the past and can assure you of exceptional and original work within the agreed deadline. I have Več
Hi! I am professional freelancer with a Master's degree in Data analytics making me a suitable person for your project. I have more than 5 years of professional experience in Data analysis. I have worked with clients Več
Olá, estou me desenvolvendo na área de ciência de dados e programação. Peço uma chance para desenvolver o projeto, contribuir e também aprender, com preço baixo mas de grande valor para o meu aprendizado.
Hello I have already fixed the code according to your purpose. Please contact me to get an update. Thanks.