Fix R code or translate simple Python function to R

Closed Posted 1 year ago Paid on delivery
Closed Paid on delivery

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)

Python C Programming R Programming Language Software Testing Discord API

Project ID: #37170793

About the project

13 proposals Remote project Active 1 year ago

13 freelancers are bidding on average $44 for this job

schoudhary1553

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 More

$70 USD in 2 days
(136 Reviews)
7.2
sonus21

Hello! I hope you're well. I'm a seasoned Python developer with over 12 years of experience, specializing in python. I understand from your description that you are looking for someone to help fix your R code or trans More

$20 USD in 7 days
(59 Reviews)
6.2
glanegonsalves

Hey there, Glane here i can help in fixing the existing R code without errors. Feel free to get in touch.

$50 USD in 1 day
(113 Reviews)
5.8
jonyahmed105

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 More

$60 USD in 2 days
(15 Reviews)
5.9
mobimubasir

Hello. I read your requirement i will fix that. Please come on chat we will discuss more about this. I will waiting your reply.

$50 USD in 1 day
(13 Reviews)
4.3
TheDataAnalysts

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

$50 USD in 2 days
(7 Reviews)
4.2
saba106

I am an expert statistician, Research Writer, and data analyst with more than five years of experience. I have full command of Excel analysis, SPSS, STATA, R LANGUAGE, AND PYTHON. I am an expert in creating time series More

$30 USD in 2 days
(10 Reviews)
4.0
darios1

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

$30 USD in 7 days
(16 Reviews)
3.7
tkmaina868

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 More

$100 USD in 2 days
(1 Review)
3.5
lincolnwriter

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 More

$50 USD in 1 day
(3 Reviews)
2.8
gabrielmonar01

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.

$10 USD in 7 days
(0 Reviews)
0.0
AmaraQamar

Hello I have already fixed the code according to your purpose. Please contact me to get an update. Thanks.

$30 USD in 3 days
(0 Reviews)
0.0