Skip to content

Commit aa8b011

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

26 files changed

+1307
-21
lines changed

.github/workflows/main-branch.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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: 'corretto'
21+
22+
- name: Setup Gradle
23+
uses: gradle/actions/setup-gradle@v4
24+
25+
- name: Change wrapper permissions
26+
run: chmod +x ./gradlew
27+
28+
- name: Build with Gradle Wrapper
29+
run: ./gradlew build
30+
31+
- name: Extract project name from Gradle
32+
id: extract_name
33+
run: |
34+
PROJECT_NAME=$(./gradlew -q printProjectName)
35+
echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV
36+
37+
- name: Extract version from Gradle
38+
id: get-version
39+
run: |
40+
VERSION=$(./gradlew -q printProjectVersion)
41+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
42+
43+
- name: Upload jar
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}.jar
47+
path: build/libs/${{ env.PROJECT_NAME }}-${{ env.VERSION }}.jar
48+
49+
- name: Upload fat jar
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: ${{ env.PROJECT_NAME }}-fat-${{ env.VERSION }}.jar
53+
path: build/libs/${{ env.PROJECT_NAME }}-fat-${{ env.VERSION }}.jar
54+
55+
build-and-push-docker:
56+
runs-on: ubuntu-latest
57+
permissions:
58+
packages: write
59+
env:
60+
REGISTRY: ghcr.io
61+
IMAGE_NAME: ${{ github.repository }}
62+
63+
steps:
64+
- name: Checkout repository
65+
uses: actions/checkout@v4
66+
67+
- name: Log in to GitHub Container Registry
68+
uses: docker/login-action@v2
69+
with:
70+
registry: ${{ env.REGISTRY }}
71+
username: ${{ github.actor }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Extract version from file
75+
id: get-version
76+
run: |
77+
VERSION=$(./gradlew -q printProjectVersion)
78+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
79+
80+
- name: Extract metadata (tags, labels) for Docker
81+
id: meta
82+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
83+
with:
84+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
85+
86+
- name: Change wrapper permissions
87+
run: chmod +x ./gradlew
88+
89+
- name: Build and push Docker image
90+
id: push
91+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
92+
with:
93+
context: .
94+
push: true
95+
tags: ${{ steps.meta.outputs.tags }}
96+
labels: ${{ steps.meta.outputs.labels }}
97+
98+
- name: Generate artifact attestation
99+
uses: actions/attest-build-provenance@v1
100+
with:
101+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
102+
subject-digest: ${{ steps.push.outputs.digest }}
103+
push-to-registry: true
104+
105+
package-and-push-helm:
106+
runs-on: ubuntu-latest
107+
permissions:
108+
contents: write
109+
110+
steps:
111+
- name: Checkout repository
112+
uses: actions/checkout@v4
113+
114+
- name: Configure Git
115+
run: |
116+
git config user.name ${{ github.actor }}
117+
git config user.email "${{ github.actor }}@users.noreply.github.com"
118+
119+
- name: Install Helm
120+
uses: azure/setup-helm@v4
121+
env:
122+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
123+
124+
- name: Run chart-releaser
125+
uses: helm/[email protected]
126+
with:
127+
charts_dir: helm
128+
env:
129+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
130+
131+
dependency-submission:
132+
runs-on: ubuntu-latest
133+
permissions:
134+
contents: write
135+
136+
steps:
137+
- name: Checkout repository
138+
uses: actions/checkout@v4
139+
140+
- name: Set up JDK 21
141+
uses: actions/setup-java@v4
142+
with:
143+
java-version: '21'
144+
distribution: 'corretto'
145+
146+
- name: Generate and submit dependency graph
147+
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 amazoncorretto:21
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 with `./gradlew build` or download already built fat jar artifact from the last successful action on https://github.com/likespro/cp-programming-stats-bot/actions
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)