Inspiration

These days, people are mostly working and learning from home and Discord has recently enjoyed widespread popularity. We wanted to build a tool that caters to Discord users who are learners and who enjoy applying learnt knowledge through real examination and competition.

What it does

The Discord bot hosts rounds of quizzes/competitions, each consisting of a series of questions. Each individual user would answer multiple-choice questions by clicking on Discord message "reactions" and reply a message directly for "short answer" questions. The bot will then calculate scores based on the correctness of the reaction time, and maintain a leaderboard for all participants. Each MC question can have more than one correct answers, and all questions may be accompanied by a media file (e.g. image, gif, video, or even code excerpt).

Please take a look at the screenshots and especially the subtitles underneath each of them. They will give you a great sense of not only DiscJudge's overall structure and technologies used, but also how the components are connected to one another.

How we built it

We built the bot with the Discord.js library and a multitude of asynchronous event listeners and callbacks in Node.js.

We used DataStax-Astra, a cloud database-service based on Apache Cassandra, to store all of our data. We provisioned a keyspace, under which we set up tables (1 for each individual problem set). On each row of a table there are a question's identifier, problem statement, type (multiple choice or short answer), up to 4 choices, correct answer, type of media file, and data of media file. We interact with the database mostly using the Stargate-REST-API-v2, and occasionally with the Cassandra Driver, DataStax-Bulk-Loader (DSBulk) or directly on the webpage. Meanwhile, DiscJudge allows for the affiliation of media files to questions. Those files could not be directly stored in the Database, and so we would need to first convert any file into Binary-large-object (Blob) by generating a string containing the hexadecimal representation of the entire binary content of the file and then upload the "blob" to Astra. Whenever DiscJudge posts a question, it retrieves the "blob" of its corresponding media file from the database, decodes the hexadecimal string, and sends the file immediately after.

This is where distributed data computation and operations come in very handy. Assume that we have dozens of questions in a quiz, and that we have a 10+ second video attached to each question, the DCP API will potentially save us a significant amount of time by running "getHexRepresentation" "jobs" for all files in parallel. Similarly, we'd use DCP "jobs" on the array of contestants to calculate post-round scores and maintain the leaderboard, thereby supporting a large number of people participating simultaneously and smoothly. We would also instantiate objects of the Worker class on our local machines' Web browsers to contribute as much computing power as we can to the organization while using their resources.

What we learned

We explored a new database (DataStax-Astra) inside out and fully from blank. We studied the several ways of doing CRUD operations to Astra and querying information directly in the online interactive console using the Cassandra Query Language (CQL). To be able to store and retrieve media files, we had to discover how to express any file in base64/text or blob format and the means to convert it back to its original state. Additionally, we picked up the DCP API along the way, learning about how to deploy tasks in Node.js that can, via parallelism, help achieve huge improvement to performance--in terms of completion time.

Challenges we ran into

The major problems we encountered were all with with the Astra database. Specifically, we suspect that some parts of their "search" endpoints were not behaving as they were documented, as they don't seem to parse the headers within the requests correctly and continually sent 4XX failure status back. Further, we observed miscellaneous issues uploading Blobs as those strings must be changed into a specific format to be accepted by Cassandra storage and that sometimes their "key length" might exceed the designated upper limit: alt text

No customer support agent for Astra work on weekends, and so we had no choice but to dig our way through the immense documentation or to search on Stack Overflow to find resolutions to all issues.

Accomplishments that we're proud of

We were able to implement plenty of functionalities (some of which are rather sophisticated) on the main bot during the 48-hour window. We've also read and understood the documentation on DataStax-Astra, DCP API, and the Blob data type, technologies and concepts that had been completely new to us. We finally successfully connected the dots and made all parts of the project (i.e. contest-administering and solution judging bot in Javascript; media file processing, uploading, and retrieval; and distributed computation) working as intended.

What's next for DiscJudge

We will strive to enable more commands and interactive features on the Discord bot, and to conduct highly comprehensive and thorough testing to ensure all users will have a seamless experience using it.

Built With

  • blob
  • cassandra-driver
  • datastax-astra
  • dcp-api.job
  • dcp-api.worker
  • discord.js
  • dsbulk
  • javascript
  • node.js
  • stargate-rest-api-v2.0.0
Share this project:

Updates