Skip to content

Commit

Permalink
feat: read osu messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stanrunge committed Dec 26, 2024
1 parent 921c6dc commit 85ec125
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/osu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the official Bun image
FROM oven/bun:1 AS base
FROM oven/bun AS base
WORKDIR /usr/src/app

# Install dependencies into temp directory (cache them to speed up future builds)
Expand Down Expand Up @@ -31,4 +31,4 @@ COPY . .
# Run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "src/index.ts" ]
ENTRYPOINT [ "bun", "run", "src/index.ts" ]
Binary file modified packages/osu/bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/osu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"dependencies": {
"@types/express": "^5.0.0",
"@types/irc": "^0.5.4",
"axios": "^1.7.9",
"express": "^4.21.2",
"irc": "0.5.0"
}
}
}
13 changes: 9 additions & 4 deletions packages/osu/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Client } from "irc";
import express from "express";
import axios from "axios";

function setupIrc() {
const client = new Client("irc.ppy.sh", process.env.IRC_USERNAME, {
const client = new Client("irc.ppy.sh", process.env.IRC_USERNAME!, {
channels: ["#osu"],
userName: process.env.IRC_USERNAME,
password: process.env.IRC_PASSWORD,
Expand All @@ -16,14 +17,18 @@ function setupIrc() {
console.log("Registered", message);
});

client.addListener("message", function (from, to, message) {
console.log(from + " => " + to + ": " + message);
client.addListener("message", async function (from, to, message) {
await axios.post("http://laravel.test/api/osu_messages", {
username: from,
channel: to,
message,
});
});

return client;
}

function setupExpress(ircClient) {
function setupExpress(ircClient: Client) {
const app = express();
app.use(express.json());

Expand Down
12 changes: 5 additions & 7 deletions packages/osu/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ name: Docker Image CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
74 changes: 74 additions & 0 deletions packages/web/app/Http/Controllers/OsuMessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Http\Controllers;

use App\Models\OsuMessage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class OsuMessageController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
Log::debug($request);

$validated = $request->validate([
'username' => 'required',
'channel' => 'required',
'message' => 'required',
]);

OsuMessage::create($validated);
}

/**
* Display the specified resource.
*/
public function show(OsuMessage $osuMessage)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(OsuMessage $osuMessage)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, OsuMessage $osuMessage)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(OsuMessage $osuMessage)
{
//
}
}
10 changes: 10 additions & 0 deletions packages/web/app/Models/OsuMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class OsuMessage extends Model
{
protected $fillable = ['username', 'channel', 'message'];
}
5 changes: 1 addition & 4 deletions packages/web/app/Services/OsuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class OsuService
{
public function __construct()
{
// $this->listenForMessages();
}
public function __construct() {}

public function getAccessToken()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ public function up(): void
$table->timestamps();
});

Schema::create('osu_messages', function (Blueprint $table) {
$table->id();
$table->string('message');
$table->string('channel');
$table->string('username');
$table->foreignIdFor(Profile::class)->nullable();
$table->timestamps();
});

}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/web/routes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

use App\Http\Controllers\OsuMessageController;
use Illuminate\Support\Facades\Route;

Route::resource('/osu_messages', OsuMessageController::class);

0 comments on commit 85ec125

Please sign in to comment.