Skip to content

Commit

Permalink
Add watchtower; Add prod docker-compose; Add user to clean command; U…
Browse files Browse the repository at this point in the history
…pdate nyxx to 3.0.0-dev.x
  • Loading branch information
l7ssha committed Dec 3, 2021
1 parent 048135a commit 82b2a1d
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 69 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Create and publish a Docker image

on:
push:
branches: ['main']
release:
types:
- created
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.4.2

- Update nyxx and its sub libs to 3.0.0-dev.x
- Add watchtower to docker-compose
- Add user filter to clean method

## 2.4.1

- Upgrade migent
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ format-apply: ## Run dart format
.PHONY: analyze
analyze: ## Run dart analyze
dart analyze

.PHONY: prod-start
prod-start: ## build and start prod docker-compose
docker-compose -f docker-compose.prod.yml up

.PHONY: prod-start-build
prod-start-build: ## build and start prod docker-compose
docker-compose -f docker-compose.prod.yml up --build

.PHONY: prod-stop
prod-stop: ## build and start prod docker-compose
docker-compose -f docker-compose.prod.yml down
8 changes: 5 additions & 3 deletions bin/running_on_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ void main(List<String> arguments) async {
"Admin commands for server management",
[
CommandOptionBuilder(CommandOptionType.subCommandGroup, "clean", 'Chat cleanup commands', options: [
CommandOptionBuilder(CommandOptionType.subCommand, "cleanup", "Cleans given number of messages. Uses cache!",
options: [CommandOptionBuilder(CommandOptionType.integer, "count", "Number of messages to clean")])
CommandOptionBuilder(CommandOptionType.subCommand, "cleanup", "Cleans given number of messages. Uses cache!", options: [
CommandOptionBuilder(CommandOptionType.integer, "count", "Number of messages to clean", required: true),
CommandOptionBuilder(CommandOptionType.user, "user", "Remove messages from given user")
])
..registerHandler(rod.cleanupSlashHandler)
])
],
guild: rod.testGuildSnowflake))
..syncOnReady(syncRule: ManualCommandSync(sync: rod.syncCommands))
..syncOnReady(syncRule: ManualCommandSync(sync: rod.getSyncCommandsOrOverride(true)))
..events.onSlashCommand.listen((event) => rod.slashCommandsTotalUsageMetric.labels([event.interaction.name]).inc());

await rod.initReminderModule(botInstance);
Expand Down
59 changes: 59 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: '3.3'
services:
running_on_dart:
build: ./
container_name: running_on_dart
env_file:
- ./.env
links:
- db
depends_on:
- db

db:
image: postgres
container_name: running_on_dart_db
restart: always
env_file:
- ./.env
volumes:
- "rod_db:/var/lib/postgresql/data"

prometheus:
image: prom/prometheus:latest
container_name: running_on_dart_prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus
restart: unless-stopped
command:
- "--config.file=/etc/prometheus/prometheus.yml"
links:
- running_on_dart

grafana:
image: grafana/grafana:latest
container_name: running_on_dart_grafana
ports:
- "127.0.0.1:9191:3000"
volumes:
- grafana-data:/var/lib/grafana
restart: unless-stopped
links:
- prometheus
depends_on:
- prometheus

watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 10 --http-api-metrics --http-api-token ${WATCHTOWER_API_KEY} running_on_dart

volumes:
rod_db:
driver: local
prometheus-data:
driver: local
grafana-data:
driver: local
28 changes: 0 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,7 @@ services:
- ./.env
volumes:
- "rod_db:/var/lib/postgresql/data"
prometheus:
image: prom/prometheus:latest
container_name: running_on_dart_prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus
restart: unless-stopped
command:
- "--config.file=/etc/prometheus/prometheus.yml"
links:
- running_on_dart

grafana:
image: grafana/grafana:latest
container_name: running_on_dart_grafana
ports:
- "127.0.0.1:9191:3000"
volumes:
- grafana-data:/var/lib/grafana
restart: unless-stopped
links:
- prometheus
depends_on:
- prometheus

volumes:
rod_db:
driver: local
prometheus-data:
driver: local
grafana-data:
driver: local
2 changes: 1 addition & 1 deletion lib/running_on_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export "src/modules/nickname_poop.dart" show nicknamePoopJoinEvent, nicknamePoop
export "src/modules/reminder/reminder.dart" show initReminderModule;
export "src/modules/settings/settings.dart" show prefixHandler, botToken, setIntents, cacheOptions, getFeaturesAsChoices;
export "src/modules/prometheus.dart";
export "src/internal/utils.dart" show syncCommands, debug, isTest, testGuildSnowflake;
export "src/internal/utils.dart" show syncCommands, debug, isTest, testGuildSnowflake, getSyncCommandsOrOverride;
10 changes: 10 additions & 0 deletions lib/src/commands/slash/admin_slash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Future<void> cleanupSlashHandler(ISlashCommandInteractionEvent event) async {
final toTake = int.parse(event.getArg('count').value.toString());
final channelLastMessages = await channel.downloadMessages(limit: toTake).toList();

try {
final userToFilter = event.interaction.resolved?.users.first;

if (userToFilter == null) {
return;
}

channelLastMessages.removeWhere((element) => element.author.id != userToFilter.id);
} on StateError {}

try {
await channel.bulkRemoveMessages(channelLastMessages);
return event.respond(MessageBuilder.content("Messages removed"), hidden: true);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/internal/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ int _approxMemberOnline = -1;

Snowflake? get testGuildSnowflake => isTest ? Snowflake(302360552993456135) : null;

bool getSyncCommandsOrOverride([bool? overrideSync]) => overrideSync ?? syncCommands;

bool isBool(String? value) {
return value != null && (value == "true" || value == "1");
}
Expand Down
28 changes: 11 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,24 @@ packages:
nyxx:
dependency: "direct main"
description:
path: "."
ref: next
resolved-ref: f68bacccd0d53eb69a4f00e823042e65e00426d8
url: "https://github.com/nyxx-discord/nyxx.git"
source: git
version: "3.0.0-dev.0"
name: nyxx
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0-dev.1"
nyxx_commander:
dependency: "direct main"
description:
path: "."
ref: next
resolved-ref: "84f6fdc9e274ca0f70cd1c36bbc1d611e4912fb8"
url: "https://github.com/nyxx-discord/nyxx_commander.git"
source: git
name: nyxx_commander
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0-dev.0"
nyxx_interactions:
dependency: "direct main"
description:
path: "."
ref: next
resolved-ref: ccfd6a3a4cd86bede2952ba35321e61003af1873
url: "https://github.com/nyxx-discord/nyxx_interactions.git"
source: git
version: "3.0.0-dev.0"
name: nyxx_interactions
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0-dev.1"
path:
dependency: transitive
description:
Expand Down
22 changes: 4 additions & 18 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: running_on_dart
version: 2.4.1
version: 2.4.2
description: Discord Bot for nyxx development
homepage: https://github.com/nyxx-discord/running_on_dart
repository: https://github.com/nyxx-discord/running_on_dart
Expand All @@ -12,9 +12,9 @@ environment:

dependencies:
logging: ^1.0.0
nyxx: ^2.0.4
nyxx_commander: ^2.0.0
nyxx_interactions: ^2.0.0
nyxx: ^3.0.0-dev.1
nyxx_commander: ^3.0.0-dev.0
nyxx_interactions: ^3.0.0-dev.0
postgres: ^2.3.2
time_ago_provider: ^4.0.0
migent:
Expand All @@ -27,17 +27,3 @@ dependencies:

dev_dependencies:
lints: ^1.0.1

dependency_overrides:
nyxx:
git:
url: 'https://github.com/nyxx-discord/nyxx.git'
ref: next
nyxx_commander:
git:
url: 'https://github.com/nyxx-discord/nyxx_commander.git'
ref: next
nyxx_interactions:
git:
url: 'https://github.com/nyxx-discord/nyxx_interactions.git'
ref: next

0 comments on commit 82b2a1d

Please sign in to comment.