This commit is contained in:
Alicia 2019-02-24 14:56:23 +00:00
parent 95754bffef
commit 3f08657c4d

View File

@ -2,18 +2,18 @@ package v1
import ( import (
"database/sql" "database/sql"
"github.com/osuYozora/api/common"
"sort"
"fmt" "fmt"
"sort"
"strconv" "strconv"
"github.com/osuYozora/common"
) )
type singleClan struct { type singleClan struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Tag string `json:"tag"` Tag string `json:"tag"`
Icon string `json:"icon"` Icon string `json:"icon"`
} }
type multiClanData struct { type multiClanData struct {
@ -53,26 +53,26 @@ func ClansGET(md common.MethodData) common.CodeMessager {
return r return r
} }
type clanMembersData struct { type clanMembersData struct {
common.ResponseBase common.ResponseBase
Members []userNotFullResponseLmao `json:"members"` Members []userNotFullResponseLmao `json:"members"`
} }
// get total stats of clan. later. // get total stats of clan. later.
type totalStats struct { type totalStats struct {
common.ResponseBase common.ResponseBase
ClanID int `json:"id"` ClanID int `json:"id"`
ChosenMode modeData `json:"chosen_mode"` ChosenMode modeData `json:"chosen_mode"`
Rank int `json:"rank"` Rank int `json:"rank"`
} }
type clanLbSingle struct { type clanLbSingle struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Tag string `json:"tag"` Tag string `json:"tag"`
Icon string `json:"icon"` Icon string `json:"icon"`
ChosenMode modeData `json:"chosen_mode"` ChosenMode modeData `json:"chosen_mode"`
Rank int `json:"rank"` Rank int `json:"rank"`
} }
type megaStats struct { type megaStats struct {
@ -115,7 +115,6 @@ func AllClanStatsGET(md common.MethodData) common.CodeMessager {
fmt.Println(brr) fmt.Println(brr)
m = 0 m = 0
} }
n := "std" n := "std"
if m == 1 { if m == 1 {
n = "taiko" n = "taiko"
@ -198,16 +197,13 @@ func AllClanStatsGET(md common.MethodData) common.CodeMessager {
return r return r
} }
func TotalClanStatsGET(md common.MethodData) common.CodeMessager { func TotalClanStatsGET(md common.MethodData) common.CodeMessager {
var ( var (
r megaStats r megaStats
rows *sql.Rows rows *sql.Rows
err error err error
) )
rows, err = md.DB.Query("SELECT id, name, description, icon FROM clans") rows, err = md.DB.Query("SELECT id, name, description, icon FROM clans")
if err != nil { if err != nil {
md.Err(err) md.Err(err)
@ -235,7 +231,7 @@ func TotalClanStatsGET(md common.MethodData) common.CodeMessager {
//RETARD CODE HAHAAAA //RETARD CODE HAHAAAA
m, brr := strconv.ParseInt(string(md.Query("m")[11]), 10, 64) m, brr := strconv.ParseInt(string(md.Query("m")[11]), 10, 64)
if brr != nil { if brr != nil {
fmt.Printf("%v", brr) fmt.Println(brr)
} }
n := "std" n := "std"
@ -248,6 +244,7 @@ func TotalClanStatsGET(md common.MethodData) common.CodeMessager {
} else { } else {
n = "std" n = "std"
} }
fmt.Println(n)
for i := 0; i < len(r.Clans); i++ { for i := 0; i < len(r.Clans); i++ {
var members clanMembersData var members clanMembersData
@ -271,7 +268,7 @@ func TotalClanStatsGET(md common.MethodData) common.CodeMessager {
`, rid) `, rid)
if err != nil { if err != nil {
fmt.Printf("%v", brr) fmt.Println(err)
} }
members.Code = 200 members.Code = 200
@ -321,7 +318,7 @@ func TotalClanStatsGET(md common.MethodData) common.CodeMessager {
}) })
for i := 0; i < len(r.Clans); i++ { for i := 0; i < len(r.Clans); i++ {
r.Clans[i].Rank = i+1 r.Clans[i].Rank = i + 1
} }
b := totalStats{} b := totalStats{}
for i := 0; i < len(r.Clans); i++ { for i := 0; i < len(r.Clans); i++ {
@ -342,9 +339,9 @@ func TotalClanStatsGET(md common.MethodData) common.CodeMessager {
} }
type isClanData struct { type isClanData struct {
Clan int `json:"clan"` Clan int `json:"clan"`
User int `json:"user"` User int `json:"user"`
Perms int `json:"perms"` Perms int `json:"perms"`
} }
type isClan struct { type isClan struct {
@ -385,21 +382,29 @@ func IsInClanGET(md common.MethodData) common.CodeMessager {
type imRetarded struct { type imRetarded struct {
common.ResponseBase common.ResponseBase
Invite string `json:"invite"` Invite string `json:"invite"`
}
type adminClan struct {
Id int `json:"user"`
Perms int `json:"perms"`
} }
func ClanInviteGET(md common.MethodData) common.CodeMessager { func ClanInviteGET(md common.MethodData) common.CodeMessager {
// big perms check lol ok // big perms check lol ok
n := common.Int(md.Query("id")) n := common.Int(md.Query("id"))
adminRetard := adminClan{}
var r imRetarded var r imRetarded
var clan int var clan int
// get user clan, then get invite // get user clan, then get invite
md.DB.QueryRow("SELECT clan FROM user_clans WHERE user = ? LIMIT 1", n).Scan(&clan) md.DB.QueryRow("SELECT user, clan, perms FROM user_clans WHERE user = ? LIMIT 1", n).Scan(&adminRetard.Id, &clan, &adminRetard.Perms)
row := md.DB.QueryRow("SELECT invite FROM clans_invites WHERE clan = ? LIMIT 1", clan).Scan(&r.Invite) if adminRetard.Perms < 8 || adminRetard.Id != md.ID() {
if row != nil { return common.SimpleResponse(500, "You are not admin of there clan")
fmt.Println(row) }
} row := md.DB.QueryRow("SELECT invite FROM clans_invites WHERE clan = ? LIMIT 1", clan).Scan(&r.Invite)
if row != nil {
fmt.Println(row)
}
return r return r
} }
@ -413,7 +418,7 @@ func ClanMembersGET(md common.MethodData) common.CodeMessager {
if r == 0 { if r == 0 {
var members clanMembersData var members clanMembersData
err := md.DB.Select(&members.Members, `SELECT users.id, users.username, users.register_datetime, users.privileges, err := md.DB.Select(&members.Members, `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, users_stats.username_aka, latest_activity, users_stats.username_aka,
users_stats.country, users_stats.user_color, users_stats.country, users_stats.user_color,
@ -427,17 +432,17 @@ INNER JOIN users_stats ON users_stats.id = uc.user
WHERE clan = ? WHERE clan = ?
ORDER BY id ASC `, i) ORDER BY id ASC `, i)
if err != nil { if err != nil {
md.Err(err) md.Err(err)
return Err500 return Err500
} }
members.Code = 200 members.Code = 200
return members return members
} else { } else {
var members clanMembersData var members clanMembersData
err := md.DB.Select(&members.Members, `SELECT users.id, users.username, users.register_datetime, users.privileges, err := md.DB.Select(&members.Members, `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, users_stats.username_aka, latest_activity, users_stats.username_aka,
users_stats.country, users_stats.user_color, users_stats.country, users_stats.user_color,
@ -451,12 +456,12 @@ INNER JOIN users_stats ON users_stats.id = uc.user
WHERE clan = ? AND perms = ? WHERE clan = ? AND perms = ?
ORDER BY id ASC `, i, r) ORDER BY id ASC `, i, r)
if err != nil { if err != nil {
md.Err(err) md.Err(err)
return Err500 return Err500
} }
members.Code = 200 members.Code = 200
return members return members
} }
} }