Simply use the following link to add the bot to the server
Discord Invite
-
This bot is a prototype, not functionally finished.
-
I plan to add a few more commands to make the bot a bit more user-friendly, one such command being the
!help
. -
The code provided should serve as a good bases to add a few more layers of functionality to the bot.
-
The code might also have some not yet identified bugs, so use at your own risk.
!track {username}#{tag}
Explanation: Finds information regarding a particular user.
The bot mainly uses Henrik's Unofficial Valorant API to get player and match information for a specified Username and Tag, for example, Liferafter#7796.
The code request information twice from two end points, mainly
/valorant/v1/account/{name}/{tag}
and
/valorant/{version}/by-puuid/{mode}/{region}/{puuid}
All the information is formatted and sent to the discord channel where the command was invoked.
The all the methods of compMatchHistory
return a boolean value, so that it is easier to manage my higly coupled code where another method cannot be invoked before another method is invoked.
The hieararchy that it follows is:
getAccData()
formatAccData()
getMmrHistory()
formatMmrData()
getPrevMmr()
The code ended up being highly coupled because of how I instantiate import class attributes.
And also becuase of my attempt to reduce the amount of class being made to the API.
Side Note - It is not highly coupled interms of Software Design, since it is just one object, that has no relations to any other object. The objects methods are too dependent on the objects other methods, to the point that it makes the object itself a bit un-intuitive. And hence I used highly-coupled to describe the amount of dependence within the code; Since one buggy method would break the rest of the code.
There are two parts to the bot itself, the discordUI.py
and matchHistory.py
.
There is also a third file for tests: tests_matchhistory.py
.
discordUI.py Is the module that holds the code for all the interactions between discord and the bot.
There are two important aspects to that code:
- Initialized the commands module so that I could directly write commands, with the prefix "!"
- Bot connects to Discords API using the a Token that should be unique to the both.
Why are these important then?
The information about the prefix and commands module should help a person write more commands for their bots.
For more information visit the discord documentation.
Second, the bots Token isn't provided in the code uploaded to github, since all bots have unique tokens that connect to particular bots, my Token could be used for malicious purposes.
To add your own Token, crate a .env
file, and add this line to it:
TOKEN = 'Your Token Here'
Make sure the .env
file exists in the same directory as the discordUI.py
.
matchHistory.py contains the class compMatchHistory
which has all the methods needed for the current bot.
getAccData()
- Returns a boolean value
- True if executed properly
- False if execution failed
- Modifies
accountData
attribute ofcompMatchHistory
- Returns a boolean value
formatAccData()
- Returns a boolean value
- True if executed properly
- False if execution failed
- Modifies
region
andpuuid
attribute ofcompMatchHistory
- Returns a boolean value
getMmrHistory()
- Returns a boolean value
- True if executed properly
- False if execution failed
- Modifies
mmrData
attribute ofcompMatchHistory
- Returns a boolean value
formatMmrData()
- Returns a boolean value
- True if executed properly
- False if execution failed
- Modifies
mmrChange
andcurrentRank
attribute ofcompMatchHistory
- Returns a boolean value
getPrevMmr()
- Returns a boolean value
- True if executed properly
- False if execution failed
- Modifies
ranks
attribute ofcompMatchHistory
- Returns a boolean value
checkErrorCode(jsonData)
- Parameters: A Json response object
- Returns a boolean value
- True if executed properly
- False if execution failed
- Modifies
statusRequest
anderrorMsg
Side Note - The Modifies information is only for when the object returns true, meaning it executes without any errors.
tests_matchHistory.py has prewritten tests to help anyone check if the code works properly if there were changes made to pre-existing methods in the compMatchHistory
The code basically just uses a bunch of assertEqual
's to see if a function is working properly for a particular username and tag pair.
It would be needed for new methods implemented to have new tests for the code.
The tests themselves use the unittest
module built into python.
The code coverage for current tests is 96%.
The current requirements.txt file contains all the third party modules, the code is dependent on.
You can simply pip-install those requirements.
You can also use the Dockerfile in this repo to build and run a Docker Image. Use the commands below in the command prompt.
cd <PATH to Dir where DockerFile and code exists>
docker build --build-arg Token=<BOT TOKEN> -t <name>:<tag> .