Skip to content
TORNLIFE More

TornSharp.NET, a C# Library for Torn API

Started by Balphagore [3719508] on in API Development.

6 replies · 133 views · thread synced · 9 days ago · View on torn.com
About this thread

Posts archived: 7 / 7 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
7
Discussion span
→
People posting
4
Likes on archived posts
4
Authority score
52 / 100
Historical score
25 / 100
Story score
31 / 100
Engagement score
52 / 100
Balphagore [3719508]

Hello all,

 

I am planning on writing a Discord bot in C# that is not yet to be disclosed but I haven't found a fresh C# library yet for working with Torn's public API v2 and I have an opportunity to develop one for the community.

 

Are there others interested in such a library? Before I start development, I can develop a public use, generic C# library to work with Torn's API including another library to interact with TornStats and YATA.

 

Let me know if you'd be interested to use it in the future and what are some big use cases you're looking for first such as market data, factioning wars, etc.

 

Those interested can let me know and I will send updates for beta testing and support. Documentation and evolution of this thread will follow development if the decision is to move forward.

feneath [2620755]

What are you going to put in the library? Something like refit can do most of the hard work and you just need to write your models. So it’s probably not worth it if that’s it.  If you are going to do rate limiting across api keys then that’s more useful. 

Balphagore [3719508]

Rate limiting is one of the big requirements of the library at the moment. I am also going over the history of the threads in this API category to collect responses from developers and input from people to help determine further requirements and specifications.

 

It'll support concurrent API connectivity and will enforce rate limiting on a API key level as well as a global level. Currently I am assuming 1k requests per minute. The Discord bot will use this library and users will be tying the knot with their Discord to the torn account via API key's as well as an API key for the bot itself that does not pertain to specific user information such as calendar events, etc.

 

I am also considering implementing caching by letting the developer pass in a provider(i.e. IMemoryCache) and cache mundane calls that do not frequently update with a configurable timespan. This will save roundtrip calls to Torn despite Torn's API having some caching too.

Yulia [3663887]

I recently built a similar system for my own C# tools that use the Torn API.

It includes an API key pool, where one can register API keys. The system keeps track of each key’s permissions. When I need to make an API call, it automatically selects a suitable key that has the required permissions and enough remaining quota. It also respects error messages returned by Torn. For example, there’s a suspension mechanism that temporarily pauses keys when issues occur. And yes, there's an additional rate limiter at the API level to ensure the system doesn’t exceed 1000 requests per minute.

Personally, I don't really see much added value in using a dedicated library for this. Polly already handles a lot. Discord is well-supported with NetCord, and Refit is there for the actual cal ls. I simply prefer wiring those components together myself, rather than relying on a library to do it for me. But well, I usually have my own preferences for how things should be structured. ;)

But I’ll be following your progress closely. ;)

miku [3165390]

Are there any benefits to using C# over python for a torn discord bot? Parsing data and setting up asynchronous commands just seems a lot easier to do in python and discord.py is an amazing library for python discord bots.

Balphagore [3719508]

This library brings benefit to C# centric developers to do more than just Discord bots. Be it, another website like TornStats that polls data from Torn. I use Python sometimes at my job, but all my work is done in C# because I've studied and coded with C# over my career.

 

I am making a Discord bot on a commission basis exclusively for a sponsor and I am using Discord.Net to power the bot while my library focuses on allowing the bot to interface with Torn.

 

The library is not exclusive to the commission project and is my a la mode for the project and also for public use while the bot remains exclusive to the sponsor.

 

I am also open to any problems that exist and could be solved with another website or bot as well to flex the library in real-world cases beyond the bot as well.