GithubHelp home page GithubHelp logo

oqixts's Introduction

Oqix logo

OqixTS

Discord BOT intended for FIT@FI server.

Build Status GitHub last commit Latest GitHub tag Latest GitHub tag


OqixTS is a bot used in FIT@FI discord. This bot has following functionalinty:

  • Verify users
  • Print out information how many credits you will receive for course recognition
  • Prune spam messages
  • Announce message
  • Restart
  • Whoami - prints user info
  • Whois - print info about user

🖥️ Development setup

This app uses NodeJS to setup dev environment use npm and run following command:

npm i

App expects some environment variables to set them you can create .env file and enter following:

DISCORD_TOKEN=<BOT_TOKEN>
CLIENT_ID=<APPLICATION_ID>
GUILD_ID=<SERVER_ID>

To get bot token you have to create bot first. How to get server id and application id you can find here.

Let bot join the server entering following url in the browser:

https://discord.com/api/oauth2/authorize?client_id={CLIENT_ID}&permissions=0&scope=bot%20applications.commands

Next run the app:

npm run start

🐳 Docker setup

This app uses docker for deployment you can build container by running:

docker build -t oqix .

For running this app in container it is suggested to setup environment variables manually running:

export DISCORD_TOKEN=<BOT_TOKEN>
export CLIENT_ID=<APPLICATION_ID>
export GUILD_ID=<SERVER_ID>

Then run the app in container using:

docker run -it -e DISCORD_TOKEN=$DISCORD_TOKEN -e CLIENT_ID=$CLIENT_ID -e GUILD_ID=$GUILD_ID oqix:latest

oqixts's People

Contributors

mimotej avatar xvanick1 avatar renovate[bot] avatar hortjar avatar tkosci avatar dependabot[bot] avatar

Stargazers

 avatar Iveta Strnadová avatar  avatar

Watchers

 avatar

oqixts's Issues

Feature request: Allow students to change their field of study role

Description of the feature

Allow users to change their assigned field of study role to a different one even through they don't officially study that desired field at the moment.

Students sometimes want to check the content in the private rooms of another field to ask questions. Alternatively, they are changing field of study and the proccess is taking too long. In both cases they have to contact admins to update their role.

Upon users request, bot would show list of buttons, where every button represents one field role. According to users choice, bot will assign to the user a role of the desired field and unassing the former field.

User can have only one field role assigned at a time.

No changes in database are needed.

Related links

Inspiration for the implementation can be found here and in the /channelmanagement slash command

Bug: In the command /uznanipredmetu the minimum FIT credits boundary is incorrect

Bug severity

minor

Bug description

According to the law, students can finish Bachelors with the minimum of 180 credits and Masters with the minimum of 120 credits. This bottom boundary seems to be not set in the bot with the connection to the semesters.

The problem is the following:
If someone magically studied bachelors only two semesters, and finished studies with 190cr, do they have available 10cr to use, or 130cr to use?

This needs to be checked.

Bot activity occasionally disappears

There's a bug in discord api making the bot activity occasionally disappear. This was working well with discordpy library, but not with current discordjs. Let's try to switch from setActivity() to setPresence() or check different solutions.

Feature request: Course ratings

Description of the feature

Allow users to rate a course and view course ratings via Oqix. It could work similarly to FITwide's ratings.

Needs a database.

At least the following should be stored for each rating: (course code is the key)

  • A score of some kind.
  • User that posted it.
  • Semester/year of absolving the course (automatic as current or allow the writer of review to specify it for older reviews).
  • Written commentary.

Then, upon users request, bot would show the average score of the course and the commentaries.

It should be considered how we want to sort the comments - easiest way would be to sort them in descending order by year/semester they relate to. Voting system as in FITwide is also an option.

Related links

#60

command /announce

In the past admins needed sometimes to announce some stuff through bot. Command example: /announce "Hello there"

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
  • arm64v8/node 19-slim
github-actions
.github/actions/build/action.yaml
  • actions/setup-node v4
  • actions/cache v4
.github/actions/prepare-image/action.yaml
  • actions/checkout v4
.github/actions/validate-user/action.yaml
  • lannonbr/repo-permission-check-action 2.0.2
  • actions/github-script v7
.github/workflows/deploy-app.yaml
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/lgtm-pr.yaml
  • actions/checkout v4
  • actions-ecosystem/action-remove-labels v1
  • actions-ecosystem/action-add-labels v1
.github/workflows/new-pr-created.yaml
  • actions/checkout v4
  • actions/github-script v7
  • actions-ecosystem/action-add-labels v1
.github/workflows/pr.yaml
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/restart-app.yaml
  • actions/checkout v4
npm
package.json
  • @discordjs/rest 2.2.0
  • @prisma/client 5.11.0
  • discord-api-types 0.37.74
  • discord.js 14.14.1
  • dotenv 16.4.5
  • jest-mock-extended 3.0.5
  • @braintree/sanitize-url 7.0.0
  • @types/cheerio 0.22.35
  • @types/jest 29.5.12
  • @types/node 18.19.24
  • @typescript-eslint/eslint-plugin 7.2.0
  • @typescript-eslint/parser 7.2.0
  • axios 1.6.8
  • cheerio 1.0.0-rc.12
  • eslint 8.57.0
  • jest 29.7.0
  • prettier 3.2.5
  • prisma 5.11.0
  • ts-jest 29.1.2
  • ts-node 10.9.2
  • typescript 5.4.2
  • nodemon 3.1.0

  • Check this box to trigger a request for Renovate to run again on this repository

Tests for existing commands

Even we are currently focusing on full transition of bot functionality from discord.py to discord.js and implementing commands, we need also someone to write a few tests.

Feature request: Ability to add/remove channels by users

Description of the feature

Users should be able to to add/remove (for themselves) subject channels as they see fit.
Acceptance criteria

  • Users can add subject channels
  • Users can remove subject channels
  • Code is tested

Related links

No response

command /verify

In the old version of the bot, there was verify feature to check if the user graduated FIT VUT and is a FI MUNI student atm. We need something similar in this new version. Below are parts of python code, enhancements are welcome.

programme_roles = {
    "Artificial intelligence and data processing": "n-UIZD",
    "Computer systems, communication and security": "n-PSKB",
    "Computer Systems, Communication and Security (eng)": "n-PSKB",
    "Informatics for secondary school teachers": "n-UCI",
    "Software Engineering": "n-SWE",
    "Software systems and services management": "n-RSSS",
    "Software Systems and Services Management (eng)": "n-RSSS",
    "Theoretical computer science": "n-TEI",
    "Visual informatics": "n-VIZ",
    "Computer Science": "d-INF",
    "Computer Science (eng)": "d-INF"
}


async def get_student_info_vut(thesis_id):
    page = requests.get('https://dspace.vutbr.cz/handle/11012/' + thesis_id + '?show=full')
    tree = html.fromstring(page.content)
    author = tree.xpath('//meta[@name="DC.creator"]/@content')[0]
    if len(author) == 0:
        return "Error: Could not retrieve VUT thesis author!"
    name = author.split(',')[1].strip()
    surname = author.split(',')[0].strip()
    return name, surname

    

async def get_student_info_muni(studies_confirmation_id):
    page = requests.get('https://is.muni.cz/confirmation-of-studies/' + studies_confirmation_id + '?lang=en')
    tree = html.fromstring(page.content)

    elements = tree.xpath("//div[@class='student_info']")
    assert len(elements) == 1
    element = elements[0]
    rows = element.xpath("./div[@class='row']")
    studies_confirmation_data = {}

    for row in rows:
        key = row.xpath("./div/span[@class='nedurazne uc']")[0].text
        value = row.xpath("./div/strong")[0].text

        # if key == 'Name' or key == 'Faculty' or key == 'Programme' or key.startswith('Status of studies as of ') or key.startswith('Confirmation issue date'):
        if key == 'Name' or key == 'Faculty' or key == 'Programme':
            studies_confirmation_data[key] = value

    return studies_confirmation_data

    
@bot.command()
async def verify(ctx, thesis_id, studies_confirmation_id):

    vut_info = await get_student_info_vut(thesis_id)
    muni_info = await get_student_info_muni(studies_confirmation_id)

    print(f"User {ctx.author} wants to verify with following data: \n\t{vut_info}\n\t{muni_info}")

    if not (vut_info[0] and vut_info[1] in muni_info['Name']):
        print(f'Error: Unable to match VUT and MUNI data for {ctx.author}')
        await ctx.reply('Error: Unable to match VUT and MUNI data. Contact admin.')

    if 'Faculty of Informatics' not in muni_info['Faculty']:
        await ctx.reply('Error: {ctx.author} is not a student of FI.')
        print(f'Error: Unable to match {ctx.author} with FI.')

    for role in ctx.author.roles:
        if role.name in programme_roles.values() or role.name == 'verified':
            try:
                await ctx.author.remove_roles(discord.utils.get(ctx.guild.roles, name=role.name), atomic=True)
            except discord.DiscordException:
                await ctx.reply(f'Error: Unable to remove role {role.name} from user {ctx.author}. Contact admin.')
                print(f'Error: Unable to remove role {role.name} from user {ctx.author}.')

    try:
        await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name=programme_roles[muni_info['Programme']]),
                                   atomic=True)
        await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name='verified'), atomic=True)

        await ctx.reply(f"Verified {ctx.author} with role {programme_roles[muni_info['Programme']]}")
        print(f"Verified user {ctx.author} with role {programme_roles[muni_info['Programme']]}.")
    except Exception:
        await ctx.reply(
            f"Error: Unable to add role {programme_roles[muni_info['Programme']]} user {ctx.author}. Contact admin.")
        print(f"Error: Unable to add/remove role {programme_roles[muni_info['Programme']]} to/from user {ctx.author}")

    await ctx.message.delete()

command /restart

Happened on python version that bot got sometimes crazy and needed a restart by admin. Would be nice to implement it also to TS version just in case ...

command /help

show commands and their description based on user permissions

Add logging to the app

It would be good for future debugging to add logging to the app.

Acceptance criteria

  • Investigate logging methods
  • Add one method to the app

Feature request: self-assign graduate role

Description of the feature

Verified users should have option to self-assign 'graduate' role to indicate to others that their studies are over.

Related links

No response

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.