Skip to content

Commit 13cb545

Browse files
committed
Added basic functionality: Global and Contests statistics monitoring and /track command to start tracking user on CodeForces
1 parent a4dea09 commit 13cb545

26 files changed

+1274
-21
lines changed

.github/workflows/main-branch.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Main Branch Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-jar:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '21'
20+
distribution: 'openjdk'
21+
22+
- name: Setup Gradle
23+
uses: gradle/actions/setup-gradle@v4
24+
25+
- name: Build with Gradle Wrapper
26+
run: ./gradlew build
27+
28+
- name: Extract project name from Gradle
29+
id: extract_name
30+
run: |
31+
PROJECT_NAME=$(./gradlew -q printProjectName)
32+
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV
33+
34+
- name: Extract version from Gradle
35+
id: get-version
36+
run: |
37+
VERSION=$(./gradlew -q printProjectVersion)
38+
echo "VERSION=$VERSION" >> $GITHUB_ENV
39+
40+
- name: Upload jar
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: ${{$PROJECT_NAME}}+"-"+${{$VERSION}}+".jar
44+
path: build/libs/${{$PROJECT_NAME}}+"-"+${{$VERSION}}+".jar
45+
46+
- name: Upload fat jar
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: ${{$PROJECT_NAME}}+"-fat-"+${{$VERSION}}+".jar
50+
path: build/libs/${{$PROJECT_NAME}}+"-fat-"+${{$VERSION}}+".jar
51+
52+
build-and-push-docker:
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v4
58+
59+
- name: Log in to GitHub Container Registry
60+
uses: docker/login-action@v2
61+
with:
62+
username: ${{ github.repository_owner }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Extract version from file
66+
id: get-version
67+
run: |
68+
VERSION=$(./gradlew -q printProjectVersion)
69+
echo "VERSION=$VERSION" >> $GITHUB_ENV
70+
71+
- name: Build Docker image
72+
run: |
73+
docker build . -t ghcr.io/${{ github.repository }}/cp-programming-stats-bot:${{ env.VERSION }}
74+
75+
- name: Push Docker image
76+
run: |
77+
docker push ghcr.io/${{ github.repository }}/cp-programming-stats-bot:${{ env.VERSION }}
78+
79+
package-and-push-helm:
80+
runs-on: ubuntu-latest
81+
82+
steps:
83+
- name: Checkout repository
84+
uses: actions/checkout@v4
85+
86+
- name: Package Helm chart
87+
run: |
88+
helm package ./helm --destination ./charts
89+
90+
- name: Publish Helm chart to GitHub Packages
91+
run: |
92+
curl -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \
93+
-X PUT \
94+
-H "Content-Type: application/gzip" \
95+
--data-binary @charts/cp-programming-stats-bot-1.0.0.tgz \
96+
https://npm.pkg.github.com/${{ github.repository_owner }}/cp-programming-stats-bot-1.0.0.tgz
97+
98+
dependency-submission:
99+
runs-on: ubuntu-latest
100+
permissions:
101+
contents: write
102+
103+
steps:
104+
- name: Checkout repository
105+
uses: actions/checkout@v4
106+
107+
- name: Set up JDK 21
108+
uses: actions/setup-java@v4
109+
with:
110+
java-version: '21'
111+
distribution: 'openjdk'
112+
113+
- name: Generate and submit dependency graph
114+
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

.gitignore

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1-
# Compiled class file
2-
*.class
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
36

4-
# Log file
5-
*.log
7+
### IntelliJ IDEA ###
8+
.idea/modules.xml
9+
.idea/jarRepositories.xml
10+
.idea/compiler.xml
11+
.idea/libraries/
12+
*.iws
13+
*.iml
14+
*.ipr
15+
out/
16+
!**/src/main/**/out/
17+
!**/src/test/**/out/
618

7-
# BlueJ files
8-
*.ctxt
19+
### Kotlin ###
20+
.kotlin
921

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
22+
### Eclipse ###
23+
.apt_generated
24+
.classpath
25+
.factorypath
26+
.project
27+
.settings
28+
.springBeans
29+
.sts4-cache
30+
bin/
31+
!**/src/main/**/bin/
32+
!**/src/test/**/bin/
1233

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
34+
### NetBeans ###
35+
/nbproject/private/
36+
/nbbuild/
37+
/dist/
38+
/nbdist/
39+
/.nb-gradle/
2140

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
24-
replay_pid*
41+
### VS Code ###
42+
.vscode/
43+
44+
### Mac OS ###
45+
.DS_Store

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM gradle:jdk21 AS build
2+
3+
WORKDIR /app
4+
5+
COPY . .
6+
7+
RUN gradle build --no-daemon
8+
9+
FROM openjdk:21-jdk-slim
10+
11+
WORKDIR /app
12+
13+
COPY --from=build /app/build/libs/*-fat-*.jar app.jar
14+
15+
CMD ["java", "-jar", "app.jar"]

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
1-
# collaborative-algo-training-discord-bot
2-
A Discord bot for automatizing collaborative algo training
1+
<p align="center">
2+
<img width="100px" src="https://github.com/likespro.png" align="center" alt="Competitive Template" />
3+
<h2 align="center">Competitive Programming Statistics Bot</h2>
4+
<p align="center">A Discord bot to track users on competitive programming platforms</p>
5+
</p>
6+
<p align="center">
7+
<a href="https://github.com/anuraghazra/github-readme-stats/actions">
8+
<img alt="Build Passing" src="https://github.com/likespro/cp-programming-stats-bot/workflows/Main Branch Workflow/badge.svg" />
9+
</a>
10+
<a href="https://github.com/likespro/cp-programming-stats-bot/graphs/contributors">
11+
<img alt="GitHub Contributors" src="https://img.shields.io/github/contributors/likespro/cp-programming-stats-bot" />
12+
</a>
13+
<a href="https://github.com/likespro/cp-programming-stats-bot/issues">
14+
<img alt="Issues" src="https://img.shields.io/github/issues/likespro/cp-programming-stats-bot?color=0088ff" />
15+
</a>
16+
<a href="https://github.com/likespro/cp-programming-stats-bot/pulls">
17+
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/likespro/cp-programming-stats-bot?color=0088ff" />
18+
</a>
19+
</p>
20+
21+
22+
23+
24+
25+
## Overview
26+
The goal of this Discord bot is to bring users' statistics from different competitive programming platforms right to Discord.
27+
## Requirements
28+
* Running MongoDB server - you can download it on www.mongodb.com
29+
* Discord bot token - you can create it on https://discord.com/developers/applications
30+
## How to use (traditional)
31+
* Build jars: `./gradlew build`
32+
* Ensure you have set all needed environment variables (see the list below)
33+
* Run built fat jar with Java 21+: `java -jar build/libs/cp-programming-stats-bot-fat-<version>.jar`
34+
## How to use (docker)
35+
* Pull image: `docker image pull ghcr.io/likespro/cp-programming-stats-bot/cp-programming-stats-bot:latest`
36+
* Run the image with `docker run cp-programming-stats-bot:latest`. You can set environment variables by `-e <VARIABLE>=<VALUE>`, for example: `docker run -e MONGODB_URL="mongodb+srv://example.com" -e MONGODB_DATABASE="stats-database" cp-programming-stats-bot:latest`
37+
## How to use (helm)
38+
* Add repository image: `helm repo add likespro https://npm.pkg.github.com/likespro`
39+
* Deploy Helm Chart: `helm install cp-programming-stats-bot cp-programming-stats-bot-1.0.0.tgz`. You can set environment variables by `--set env.<VARIABLE>=<VALUE>`, for example: `helm install cp-programming-stats-bot cp-programming-stats-bot-1.0.0.tgz --set env.MONGODB_URL="mongodb+srv://example.com" --set env.MONGODB_DATABASE="stats-database"`
40+
## Environment variables
41+
* Set `MONGODB_URL` environment variable to valid URL of your MongoDB server, for example: `mongodb+srv://[username:password@]host[/[defaultauthdb][?options]]`
42+
* [ Optional ] Set `MONGODB_DATABASE` environment variable to valid MongoDB database name. If not specified, `cp-programming-stats-bot` will be used as name
43+
* [ Optional ] Set `DISCORD_BOT_TOKEN` environment variable to valid Discord bot token. If not specified, you will need to set `<database>/misc/config/discordBotToken` field manually after the first launch
44+
* [ Optional ] Set `DISCORD_GUILD_ID` environment variable to valid Discord Guild ID. You can get ID of any guild by enabling Developer mode in `Discord/Settings/Advanced` and then right-click on the Guild you want to use and copy its ID. If not specified, you will need to set `<database>/misc/config/discordGuildId` field manually after the first launch
45+
* [ Optional ] Set `DISCORD_GLOBAL_STATISTICS_CHANNEL_ID` environment variable to valid ID of Discord text channel where to publish global statistics. You can get ID of any text channel by enabling Developer mode in `Discord/Settings/Advanced` and then right-click on the text channel you want to use and copy its ID. If not specified, bot will try to automatically find a text channel with name "statistics". If no such channels were found, bot will create a new text channel with this name
46+
* [ Optional ] Set `DISCORD_CONTESTS_STATISTICS_CHANNEL_ID` environment variable to valid ID of Discord text channel where to publish contests statistics. You can get ID of any text channel by enabling Developer mode in `Discord/Settings/Advanced` and then right-click on the text channel you want to use and copy its ID. If not specified, bot will try to automatically find a text channel with name "contests-statistics". If no such channels were found, bot will create a new text channel with this name

build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '2.0.20'
3+
}
4+
5+
group = 'eth.likespro'
6+
version = '1.0.0'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
dependencies {
12+
implementation 'de.vandermeer:asciitable:0.3.2'
13+
implementation 'org.json:json:20231013'
14+
implementation 'io.projectreactor:reactor-core:3.6.10'
15+
implementation 'org.mongodb:mongodb-driver-reactivestreams:5.1.4'
16+
implementation 'io.github.microutils:kotlin-logging-jvm:2.0.11'
17+
implementation 'ch.qos.logback:logback-classic:1.4.12'
18+
implementation "net.dv8tion:JDA:5.2.1"
19+
testImplementation 'org.jetbrains.kotlin:kotlin-test'
20+
}
21+
22+
test {
23+
useJUnitPlatform()
24+
}
25+
kotlin {
26+
jvmToolchain(21)
27+
}
28+
tasks.jar{
29+
manifest {
30+
attributes 'Main-Class': 'eth.likespro.MainKt'
31+
}
32+
}
33+
tasks.register('fatJar', Jar) {
34+
manifest {
35+
attributes 'Main-Class': 'eth.likespro.MainKt'
36+
}
37+
archiveBaseName = rootProject.name + '-fat'
38+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
39+
from { configurations.runtimeClasspath.collect { println("Packing "+it.name+" into fatJar"); it.isDirectory() ? it : zipTree(it) } } {
40+
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
41+
}
42+
exclude("META-INF/*.RSA", "META-INF/*.DSA", "META-INF/*.SF")
43+
with jar
44+
exclude("META-INF/*.RSA", "META-INF/*.DSA", "META-INF/*.SF")
45+
}
46+
tasks.build{
47+
dependsOn(fatJar)
48+
}
49+
tasks.register('printProjectName') {
50+
doLast {
51+
println rootProject.name
52+
}
53+
}
54+
tasks.register('printProjectVersion') {
55+
doLast {
56+
println version
57+
}
58+
}

0 commit comments

Comments
 (0)