Giter Club home page Giter Club logo

infinipy's Introduction

infinipy

Okay, hear me out:

I know about ibl.py. I made this Library out of boredom, pretty much.

PLUS: InfiniPy has some neat features - like the endpoint_for function.

Get started:

import infinipy

USER_ID = 899722893603274793
BOT_ID  = 909882795768315986
user = infinipy.fetchUserSync(USER_ID) # Will return infinipy.core.User()
bot = infinipy.fetchBotSync(BOT_ID) # Will return infinipy.core.Bot()

Examples:

print("Bot Stats:")
print("Votes: "+str(bot.analytica['votes'])
print("User Stats:")
print("Nick: " + user.name + "\nBio: "+ user.about) 

Determining if Someone's a User or a bot using endpoint_for()

Ah yes, the Problem of determining if someone's a Bot or not...
So, let's assume that you want to make a bot that can get Infos using an info command
BUT it must be able to detect wether you specified a User or a Bot.

Well, the infinipy.helpers module added in V0.2 should be able to help you!

In theory, this is the code:

from infinipy.helpers import APISession, endpoint_for

session = APISession("BOT_ID")
obj = session.fetch()

In a Bot maybe like this:

@client.command()
async def iblinfo(ctx,_Id):
  session = APISession(_Id)
  object = session.fetch()
  await ctx.send(object.name)

And that's it for V0.2!

Update Bot Stats

Okay, you want everybody to see how cool your Bot is. That's great!
In V0.3, I have added APISessions to do exactly that!

Whether you're using a script to just post stats there, or want to real-time update your Bot's Statistics on IBL, I gotcha!

For simple Scripts, I recommend to use the SyncAPISession Class:

In theory, usage would look like this:

from infinipy import SyncAPISession

api = SyncAPISession("api_key")
api.postStats(shard_count, server_count)

While in a script, it could look something like this:

from infinipy import SyncAPISession
from dotenv import load_dotenv
import os
from discordbot import botclient

load_dotenv()

api = SyncAPISession(os.environ.get("ibl_api_key"))
api.postStats(bot.shards,len(bot.guilds))

Async is the same, but postStats must be awaited.
This is recommended to post real-time stats, like this:

from infinipy import AsyncAPISession
from dotenv import load_dotenv
import os
load_dotenv()

@bot.event
async def on_guild_join(guild):
  api = AsyncAPISession(os.environ.get("ibl_api_key"))
  await api.postStats(bot.shards,len(bot.guilds))

Note, that on both Classes you can get the API's response like this:

response = api.session["UPDATE_RESPONSE"]
print(response)

Adding an AutoPoster because I'm bored

AutoPosters update the Bot's statistics every so and so seconds, kinda like this:

from infinipy.helpers import AutoStatsUpdater
from mycoolbot import bot # Your Bot instance

interval = 120 # Must be >= 120

poster = AutoStatsUpdater(bot,"API_KEY_HERE",interval)
poster.start()

Hope to see you soon!
~ ZeroTwo36

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.