Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33e1552ce1 | ||
|
|
d81af99e36 | ||
|
|
70cf457e6f |
+22
-34
@@ -17,46 +17,34 @@ jobs:
|
|||||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||||
- uses: actions/checkout@v2
|
- 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: us-east-1
|
|
||||||
|
|
||||||
- name: Login to Amazon ECR
|
|
||||||
id: login-ecr
|
|
||||||
uses: aws-actions/amazon-ecr-login@v1
|
|
||||||
|
|
||||||
- name: Get Version
|
- name: Get Version
|
||||||
id: get_version
|
id: get_version
|
||||||
uses: battila7/get-version-action@v2.0.0
|
uses: battila7/get-version-action@v2.0.0
|
||||||
|
|
||||||
- name: Build, tag, and push image to Amazon ECR
|
- name: Build container image
|
||||||
id: build-image
|
|
||||||
env:
|
env:
|
||||||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
||||||
ECR_REPOSITORY: prepbot
|
|
||||||
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
|
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
|
||||||
run: |
|
run: docker build -t registry.digitalocean.com/djpianalto/prepbot:$IMAGE_TAG .
|
||||||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
|
||||||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
||||||
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
|
||||||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
|
|
||||||
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
|
|
||||||
|
|
||||||
- name: Fill in the new image ID in the Amazon ECS task definition
|
- name: Install doctl
|
||||||
id: task-def
|
uses: digitalocean/action-doctl@v2
|
||||||
uses: aws-actions/amazon-ecs-render-task-definition@v1
|
|
||||||
with:
|
with:
|
||||||
task-definition: task-definition.json
|
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
|
||||||
container-name: "prepbot"
|
|
||||||
image: ${{ steps.build-image.outputs.image }}
|
|
||||||
|
|
||||||
- name: Deploy Amazon ECS task definition
|
- name: Login to DigitalOcean Container Registry with short-lived credentials
|
||||||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
|
run: doctl registry login --expiry-seconds 600
|
||||||
with:
|
|
||||||
task-definition: ${{ steps.task-def.outputs.task-definition }}
|
- name: Push image to DigitalOcean Container Registry
|
||||||
service: "prepbot"
|
run: docker push registry.digitalocean.com/djpianalto/prepbot
|
||||||
cluster: "discord-bots"
|
|
||||||
wait-for-service-stability: true
|
- name: Update deployment file
|
||||||
|
run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|registry.digitalocean.com/djpianalto/prepbot:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml
|
||||||
|
|
||||||
|
- name: Save DigitalOcean kubeconfig with short-lived credentials
|
||||||
|
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 discord-bots
|
||||||
|
|
||||||
|
- name: Deploy to DigitalOcean Kubernetes
|
||||||
|
run: kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
|
||||||
|
|
||||||
|
- name: Verify deployment
|
||||||
|
run: kubectl rollout status deployment/prepbot
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: prepbot
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: prepbot
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: prepbot
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxSurge: 1
|
||||||
|
maxUnavailable: 1
|
||||||
|
minReadySeconds: 120
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: prepbot
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: prepbot
|
||||||
|
image: <IMAGE>
|
||||||
|
env:
|
||||||
|
- name: DISCORD_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: prepbot
|
||||||
|
key: discord_token
|
||||||
@@ -21,23 +21,48 @@ func CleanAmazonURLs(s *discordgo.Session, message *discordgo.MessageCreate) {
|
|||||||
amazonRegexString := `(http|https):\/\/((?:[\w-_\.]*)amazon(?:\.[\w\-_]+)+)([\w\/\-\.,@?^=%&~\+#]*[\w\-\@?^=%&/~\+#])?`
|
amazonRegexString := `(http|https):\/\/((?:[\w-_\.]*)amazon(?:\.[\w\-_]+)+)([\w\/\-\.,@?^=%&~\+#]*[\w\-\@?^=%&/~\+#])?`
|
||||||
amazonRegex := regexp.MustCompile(amazonRegexString)
|
amazonRegex := regexp.MustCompile(amazonRegexString)
|
||||||
urls := amazonRegex.FindAllString(message.Content, -1)
|
urls := amazonRegex.FindAllString(message.Content, -1)
|
||||||
if len(urls) == 0 {
|
if len(urls) != 0 {
|
||||||
return
|
|
||||||
}
|
for _, url := range urls {
|
||||||
for _, url := range urls {
|
if strings.Contains(url, "ref=") || strings.Contains(url, "?") {
|
||||||
if strings.Contains(url, "ref=") || strings.Contains(url, "?") {
|
parts := strings.Split(url, "/")
|
||||||
parts := strings.Split(url, "/")
|
new := strings.Join(parts[:len(parts)-1], "/")
|
||||||
new := strings.Join(parts[:len(parts)-1], "/")
|
if strings.Contains(new, "ref=") {
|
||||||
if strings.Contains(new, "ref=") {
|
parts = strings.Split(new, "ref=")
|
||||||
parts = strings.Split(new, "ref=")
|
new = parts[0]
|
||||||
new = parts[0]
|
}
|
||||||
|
content = strings.ReplaceAll(content, url, new)
|
||||||
}
|
}
|
||||||
content = strings.ReplaceAll(content, url, new)
|
}
|
||||||
|
_, err := sendWebhook(s, message, message.ChannelID, content)
|
||||||
|
if err == nil {
|
||||||
|
s.ChannelMessageDelete(message.ChannelID, message.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
webhook, err := s.WebhookCreate(message.ChannelID, message.ID, "")
|
message.Content = content
|
||||||
|
urlRegexString := `http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+`
|
||||||
|
urlRegex := regexp.MustCompile(urlRegexString)
|
||||||
|
urls = urlRegex.FindAllString(message.Content, -1)
|
||||||
|
if len(urls) != 0 {
|
||||||
|
moveNewsLinks(s, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveNewsLinks(s *discordgo.Session, message *discordgo.MessageCreate) {
|
||||||
|
linkChannel := "784855106239332352"
|
||||||
|
chatChannel := "777679317878177804"
|
||||||
|
if message.ChannelID == chatChannel {
|
||||||
|
_, err := sendWebhook(s, message, linkChannel, message.Content)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendWebhook(s *discordgo.Session, message *discordgo.MessageCreate, channelID, content string) (string, error) {
|
||||||
|
webhook, err := s.WebhookCreate(channelID, message.ID, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
defer s.WebhookDelete(webhook.ID)
|
defer s.WebhookDelete(webhook.ID)
|
||||||
var name string
|
var name string
|
||||||
@@ -51,9 +76,9 @@ func CleanAmazonURLs(s *discordgo.Session, message *discordgo.MessageCreate) {
|
|||||||
Username: name,
|
Username: name,
|
||||||
AvatarURL: message.Author.AvatarURL(""),
|
AvatarURL: message.Author.AvatarURL(""),
|
||||||
}
|
}
|
||||||
_, err = s.WebhookExecute(webhook.ID, webhook.Token, true, params)
|
w, err := s.WebhookExecute(webhook.ID, webhook.Token, true, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return "", err
|
||||||
}
|
}
|
||||||
s.ChannelMessageDelete(message.ChannelID, message.ID)
|
return w.ID, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user