-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 500891f
Showing
36 changed files
with
2,398 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Docker | ||
|
||
on: | ||
pull_request: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- master | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
# Run tests for any PRs. | ||
push: | ||
|
||
env: | ||
# Image name | ||
IMAGE_NAME: gamestats-telegram | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
push: | ||
|
||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
|
||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# This workflow will build and push a new container image to Amazon ECR, | ||
# and then will deploy a new task definition to Amazon ECS, when a release is created | ||
# | ||
# To use this workflow, you will need to complete the following set-up steps: | ||
# | ||
# 1. Create an ECR repository to store your images. | ||
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. | ||
# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name. | ||
# Replace the value of `aws-region` in the workflow below with your repository's region. | ||
# | ||
# 2. Create an ECS task definition, an ECS cluster, and an ECS service. | ||
# For example, follow the Getting Started guide on the ECS console: | ||
# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun | ||
# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names. | ||
# | ||
# 3. Store your ECS task definition as a JSON file in your repository. | ||
# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. | ||
# Replace the value of `task-definition` in the workflow below with your JSON file's name. | ||
# Replace the value of `container-name` in the workflow below with the name of the container | ||
# in the `containerDefinitions` section of the task definition. | ||
# | ||
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. | ||
# See the documentation for each action used below for the recommended IAM policies for this IAM user, | ||
# and best practices on handling the access key credentials. | ||
|
||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
name: Deploy to Amazon ECS | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: eu-central-1 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: gamestats-telegram | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
# Build a docker container and | ||
# push it to ECR so that it can | ||
# be deployed to ECS. | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | ||
- name: Fill in the new image ID in the Amazon ECS task definition | ||
id: task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: task-definition.json | ||
container-name: gamestats-telegram | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: gamestats-telegram | ||
cluster: gametools | ||
wait-for-service-stability: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM python:3 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
ENV token 2023757880:AAEJxQ4483PnCDHPmrKgh7w1C4HBI4mP5Ng | ||
ENV redishost redis-availability.1e8uve.ng.0001.euc1.cache.amazonaws.com | ||
ENV redisport 6379 | ||
ENV redispass '' | ||
|
||
COPY ./requirements.txt requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# https://github.com/goverfl0w/discord-interactions/ | ||
COPY . . | ||
|
||
CMD python ./app.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# https://docs.aiogram.dev/en/latest/ | ||
import re | ||
import os | ||
import asyncio | ||
from battlefield.api.api_requests import onReadyCheck | ||
import logging | ||
from aiogram import Bot, Dispatcher, executor, types | ||
from aiogram.contrib.fsm_storage.memory import MemoryStorage | ||
from aiogram.dispatcher.filters.state import State, StatesGroup | ||
|
||
API_TOKEN = os.environ["token"] | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
class StatState(StatesGroup): | ||
bf2 = State() | ||
bf3 = State() | ||
bfh = State() | ||
bf4 = State() | ||
bf1 = State() | ||
bf5 = State() | ||
|
||
bf2weapongraph = State() | ||
bf3weapongraph = State() | ||
bfhweapongraph = State() | ||
bf4weapongraph = State() | ||
bf1weapongraph = State() | ||
bf5weapongraph = State() | ||
|
||
bf2vehiclegraph = State() | ||
bf3vehiclegraph = State() | ||
bfhvehiclegraph = State() | ||
bf4vehiclegraph = State() | ||
bf1vehiclegraph = State() | ||
bf5vehiclegraph = State() | ||
|
||
|
||
# Initialize bot and dispatcher | ||
bot = Bot(token=API_TOKEN) | ||
|
||
storage = MemoryStorage() | ||
dp = Dispatcher(bot, storage=storage) | ||
|
||
|
||
@dp.message_handler(commands=["start", "help"]) | ||
async def send_welcome(message: types.Message): | ||
""" | ||
This handler will be called when user sends `/start` or `/help` command | ||
""" | ||
await message.reply( | ||
"This is the first initial version of the gamestats bot for telegram\nWe will start by adding the main commands:\n/bf1stats, /bf5stats, /bf4stats etc..." | ||
) | ||
|
||
|
||
from battlefield.handlers import * | ||
|
||
if __name__ == "__main__": | ||
asyncio.ensure_future(onReadyCheck()) | ||
executor.start_polling(dp, skip_updates=True) |
Empty file.
Oops, something went wrong.