This commit is contained in:
Fijxu 2024-08-25 23:28:13 -04:00
commit b837512329
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
15 changed files with 233 additions and 0 deletions

0
config.yml Normal file
View file

30
shard.lock Normal file
View file

@ -0,0 +1,30 @@
version: 2.0
shards:
backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.2
db:
git: https://github.com/crystal-lang/crystal-db.git
version: 0.13.1
exception_page:
git: https://github.com/crystal-loot/exception_page.git
version: 0.4.1
kemal:
git: https://github.com/kemalcr/kemal.git
version: 1.5.0
radix:
git: https://github.com/luislavena/radix.git
version: 0.4.1
redis:
git: https://github.com/jgaskins/redis.git
version: 0.9.0
sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git
version: 0.21.0

21
shard.yml Normal file
View file

@ -0,0 +1,21 @@
name: vanity-tester-backend
version: 0.1.0
authors:
- Fijxu <fijxu@nadeko.net>
targets:
vanity-tester-backend:
main: src/vanity-tester-backend.cr
dependencies:
kemal:
github: kemalcr/kemal
sqlite3:
github: crystal-lang/crystal-sqlite3
redis:
github: jgaskins/redis
crystal: ">= 1.13.1"
license: MIT

2
spec/spec_helper.cr Normal file
View file

@ -0,0 +1,2 @@
require "spec"
require "../src/vanity-tester-backend"

View file

@ -0,0 +1,9 @@
require "./spec_helper"
describe Vanity::Tester::Backend do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

17
src/config.cr Normal file
View file

@ -0,0 +1,17 @@
require "yaml"
class Config
include YAML::Serializable
property port : Int32 = 8090
property db : String = "./db.sqlite3"
property dbTableName : String = "files"
property redisUrl : String = "127.0.0.1:6379"
def self.load
config_file = "./config.yml"
config_yaml = File.read(config_file)
config = Config.from_yaml(config_yaml)
config
end
end

30
src/handling.cr Normal file
View file

@ -0,0 +1,30 @@
require "wait_group"
macro xd(ident)
Providers::{{ident}}.get_badges
end
module Handlers
extend self
@@channel = Channel(JSON::Any).new
@@erm = [] of JSON::Any | Nil
@@buhh = ["bttv", "chatty"]
def buh
@@buhh.each do |iden|
spawn do
@@erm << Test.test(iden)
# chatterino_badges = Providers::Chatterino.get_badges
# chatty_badges = Providers::Chatty.get_badges
# ffz_badges = Providers::FFZ.get_badges
# dankchat_badges = Providers::DankChat.get_badges
end
end
pp @@erm
end
def parse_badges(env)
buh
end
end

3
src/providers/7tv.cr Normal file
View file

@ -0,0 +1,3 @@
module Providers::SevenTV
end

8
src/providers/bttv.cr Normal file
View file

@ -0,0 +1,8 @@
module Providers::BTTV
extend self
def get_badges
res = HTTP::Client.get("https://api.betterttv.net/3/cached/badges/twitch", headers: HEADERS)
return JSON.parse(res.body)
end
end

View file

@ -0,0 +1,8 @@
module Providers::Chatterino
extend self
def get_badges
res = HTTP::Client.get("https://api.chatterino.com/badges", headers: HEADERS)
return JSON.parse(res.body)
end
end

8
src/providers/chatty.cr Normal file
View file

@ -0,0 +1,8 @@
module Providers::Chatty
extend self
def get_badges
res = HTTP::Client.get("https://tduva.com/res/badges", headers: HEADERS)
return JSON.parse(res.body)
end
end

View file

@ -0,0 +1,9 @@
# const removedBadges = ['DankChat Top Supporter'];
module Providers::DankChat
extend self
def get_badges
res = HTTP::Client.get("https://flxrs.com/api/badges", headers: HEADERS)
return JSON.parse(res.body)
end
end

View file

@ -0,0 +1,52 @@
# export async function getBadges() {
# const getBadges = await fetch(`${window.cors}https://api.frankerfacez.com/v1/badges/ids`);
# return await getBadges.json();
# }
# export async function getChannel(channelID) {
# try {
# const getChannel = await fetch(`${window.cors}https://api.frankerfacez.com/v1/room/id/${channelID}`);
# const channelData = (await getChannel.json()).room;
# let moderatorBadge = null;
# if (channelData.moderator_badge) {
# moderatorBadge = getLastValue(channelData.mod_urls);
# }
# let vipBadge = null;
# if (channelData.vip_badge) {
# vipBadge = getLastValue(channelData.vip_badge);
# }
# return { moderatorBadge, vipBadge };
# } catch {
# return { moderatorBadge: null, vipBadge: null };
# }
# }
# export const fallback = {
# badges: [],
# users: {},
# };
# export const customFallback = {
# moderatorBadge: null,
# vipBadge: null,
# };
# function getLastValue(obj) {
# return obj[Object.keys(obj)[Object.keys(obj).length - 1]];
# }
module Providers::FFZ
extend self
def get_badges
res = HTTP::Client.get("https://api.frankerfacez.com/v1/badges/ids", headers: HEADERS)
return JSON.parse(res.body)
end
# def get_channel(channel_id : String)
# res = HTTP::Client.get("https://api.frankerfacez.com/v1/room/id/#{channel_id}", headers: HEADERS)
# channel_data = JSON.parse(res.body)
end

12
src/providers/prov.cr Normal file
View file

@ -0,0 +1,12 @@
module Test
def self.test(exp)
case exp
when "bttv"
res = HTTP::Client.get("https://api.betterttv.net/3/cached/badges/twitch", headers: HEADERS)
return JSON.parse(res.body)
when "chatty"
res = HTTP::Client.get("https://tduva.com/res/badges", headers: HEADERS)
return JSON.parse(res.body)
end
end
end

View file

@ -0,0 +1,24 @@
require "kemal"
require "redis"
require "sqlite3"
require "db"
require "http/client"
require "./config"
require "./handling"
require "./providers/**"
CONFIG = Config.load
Kemal.config.port = CONFIG.port
Kemal.config.shutdown_message = false
Kemal.config.app_name = "vanity-tester-backend"
SQL = DB.open("sqlite3://#{CONFIG.db}")
REDIS_DB = Redis::Client.new(CONFIG.redisUrl)
HEADERS = HTTP::Headers{"User-Agent" => "Vanity-Tester-Backend/0.1.0"}
get "/badges" do |env|
Handlers.parse_badges(env)
end
Kemal.run