From b8375123291ab4d51c26a7c1736a324746091437 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sun, 25 Aug 2024 23:28:13 -0400 Subject: [PATCH] asdhji --- config.yml | 0 shard.lock | 30 +++++++++++++++++ shard.yml | 21 ++++++++++++ spec/spec_helper.cr | 2 ++ spec/vanity-tester-backend_spec.cr | 9 ++++++ src/config.cr | 17 ++++++++++ src/handling.cr | 30 +++++++++++++++++ src/providers/7tv.cr | 3 ++ src/providers/bttv.cr | 8 +++++ src/providers/chatterino.cr | 8 +++++ src/providers/chatty.cr | 8 +++++ src/providers/dankChat.cr | 9 ++++++ src/providers/frankerFazeZ.cr | 52 ++++++++++++++++++++++++++++++ src/providers/prov.cr | 12 +++++++ src/vanity-tester-backend.cr | 24 ++++++++++++++ 15 files changed, 233 insertions(+) create mode 100644 config.yml create mode 100644 shard.lock create mode 100644 shard.yml create mode 100644 spec/spec_helper.cr create mode 100644 spec/vanity-tester-backend_spec.cr create mode 100644 src/config.cr create mode 100644 src/handling.cr create mode 100644 src/providers/7tv.cr create mode 100644 src/providers/bttv.cr create mode 100644 src/providers/chatterino.cr create mode 100644 src/providers/chatty.cr create mode 100644 src/providers/dankChat.cr create mode 100644 src/providers/frankerFazeZ.cr create mode 100644 src/providers/prov.cr create mode 100644 src/vanity-tester-backend.cr diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/shard.lock b/shard.lock new file mode 100644 index 0000000..092d688 --- /dev/null +++ b/shard.lock @@ -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 + diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..87fd943 --- /dev/null +++ b/shard.yml @@ -0,0 +1,21 @@ +name: vanity-tester-backend +version: 0.1.0 + +authors: + - Fijxu + +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 diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100644 index 0000000..17f0443 --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/vanity-tester-backend" diff --git a/spec/vanity-tester-backend_spec.cr b/spec/vanity-tester-backend_spec.cr new file mode 100644 index 0000000..1028b0f --- /dev/null +++ b/spec/vanity-tester-backend_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Vanity::Tester::Backend do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/src/config.cr b/src/config.cr new file mode 100644 index 0000000..6b03ef2 --- /dev/null +++ b/src/config.cr @@ -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 diff --git a/src/handling.cr b/src/handling.cr new file mode 100644 index 0000000..7a094d8 --- /dev/null +++ b/src/handling.cr @@ -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 diff --git a/src/providers/7tv.cr b/src/providers/7tv.cr new file mode 100644 index 0000000..29bda48 --- /dev/null +++ b/src/providers/7tv.cr @@ -0,0 +1,3 @@ +module Providers::SevenTV + +end \ No newline at end of file diff --git a/src/providers/bttv.cr b/src/providers/bttv.cr new file mode 100644 index 0000000..ba8a0b9 --- /dev/null +++ b/src/providers/bttv.cr @@ -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 diff --git a/src/providers/chatterino.cr b/src/providers/chatterino.cr new file mode 100644 index 0000000..08531ea --- /dev/null +++ b/src/providers/chatterino.cr @@ -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 \ No newline at end of file diff --git a/src/providers/chatty.cr b/src/providers/chatty.cr new file mode 100644 index 0000000..b2014b1 --- /dev/null +++ b/src/providers/chatty.cr @@ -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 \ No newline at end of file diff --git a/src/providers/dankChat.cr b/src/providers/dankChat.cr new file mode 100644 index 0000000..3e57227 --- /dev/null +++ b/src/providers/dankChat.cr @@ -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 \ No newline at end of file diff --git a/src/providers/frankerFazeZ.cr b/src/providers/frankerFazeZ.cr new file mode 100644 index 0000000..ab74d15 --- /dev/null +++ b/src/providers/frankerFazeZ.cr @@ -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 diff --git a/src/providers/prov.cr b/src/providers/prov.cr new file mode 100644 index 0000000..3183fb2 --- /dev/null +++ b/src/providers/prov.cr @@ -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 diff --git a/src/vanity-tester-backend.cr b/src/vanity-tester-backend.cr new file mode 100644 index 0000000..48c587d --- /dev/null +++ b/src/vanity-tester-backend.cr @@ -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 \ No newline at end of file