Skip to content

Commit

Permalink
Merge pull request #49 from Quaver/clan-chat-channels
Browse files Browse the repository at this point in the history
Fix & add clan tag/name to channel description
  • Loading branch information
Swan authored Oct 17, 2024
2 parents 7475a51 + ddbd6f0 commit 4907265
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 4 additions & 4 deletions chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Initialize() {
}

for _, clan := range clans {
AddClanChannel(clan.Id)
AddClanChannel(clan)
}

_ = sessions.AddUser(Bot)
Expand Down Expand Up @@ -257,10 +257,10 @@ func addChannel(channel *Channel) {
}

// AddClanChannel Adds a new clan channel
func AddClanChannel(clanId int) *Channel {
name := fmt.Sprintf("#clan_%v", clanId)
func AddClanChannel(clan *db.Clan) *Channel {
name := fmt.Sprintf("#clan_%v", clan.Id)

channel := NewChannel(ChannelTypeClan, name, "Communicate with your fellow clan members",
channel := NewChannel(ChannelTypeClan, name, fmt.Sprintf("[%v] %v - Private Clan Chat", clan.Tag, clan.Name),
false, false, false, "")

addChannel(channel)
Expand Down
14 changes: 13 additions & 1 deletion db/clans.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Clan struct {
Customizable bool `db:"customizable"`
}

// GetAllClans Retrieves all of the clans in the db
// GetAllClans Retrieves all the clans in the db
func GetAllClans() ([]*Clan, error) {
result := make([]*Clan, 0)

Expand All @@ -22,3 +22,15 @@ func GetAllClans() ([]*Clan, error) {

return result, nil
}

func GetClanById(id int) (*Clan, error) {
var clan Clan

err := SQL.Select(&clan, "SELECT id, owner_id, name, tag, customizable FROM clans")

if err != nil && err != sql.ErrNoRows {
return nil, err
}

return &clan, nil
}
14 changes: 10 additions & 4 deletions handlers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,18 @@ func joinChatChannels(user *sessions.User) {

channel := chat.GetChannelByName(name)

if channel != nil {
channel.AddUser(user)
return
if channel == nil {
clan, err := db.GetClanById(int(user.Info.ClanId.Int32))

if err != nil {
log.Println("Error retrieving clan by id: ", err)
return
}

channel = chat.AddClanChannel(clan)
}

channel = chat.AddClanChannel(int(user.Info.ClanId.Int32))
sessions.SendPacketToUser(packets.NewServerAvailableChatChannel(channel.Name, channel.Description), user)
channel.AddUser(user)
}
}
Expand Down

0 comments on commit 4907265

Please sign in to comment.