Giter Site home page Giter Site logo

chadango's People

Contributors

dependabot[bot] avatar n0h4rt avatar

Watchers

 avatar

chadango's Issues

Add Persistence interface

This will allow Persistence to be implemented with other options besides a gob file, such as Redis, a Database, etc.

Something like this:

type Persistence interface {
	Initialize() error
	StartAutoSave(context.Context)
	Close() error
	GetBotData() *SyncMap[string, any]
	GetChatData(string) *SyncMap[string, any]
}

Some typos

chadango/constants.go

Lines 55 to 57 in 20a1771

ErrConnectionClosed = errors.New("connection closed")
ErrRetryEnds = errors.New("connection closed")

chadango/constants.go

Lines 77 to 81 in 20a1771

ErrClearFailed = errors.New("clear failed")
ErrAddModFailed = errors.New("clear failed")
ErrUpdateModFailed = errors.New("clear failed")
ErrRemoveModFailed = errors.New("clear failed")

Ineffective error assignment

The error assignment inside the callback becomes ineffective as it gets overridden by SyncSend. This issue occurs in various methods, including methods in the group.go file.

chadango/private.go

Lines 257 to 290 in 20a1771

// SendMessage sends a private message with the specified text to the username.
func (p *Private) SendMessage(username, text string) (err error) {
cb := func(frame string) bool {
head, _, _ := strings.Cut(frame, ":")
switch head {
case "show_fw":
err = ErrFloodWarning
return true
case "toofast":
err = ErrFloodBanned
return true
case "show_offline_limit":
// The maximum number of unread messages is 51.
// show_offline_limit:nekonyan
err = ErrOfflineLimit
return true
default:
p.events <- frame
}
return false
}
username = strings.ToLower(username)
text = fmt.Sprintf(`<n%s/><m v="1"><g x%02ds%s="%s">%s</g></m>`, p.NameColor, p.TextSize, p.TextColor, p.TextFont, text)
// The "msg" command does not produce a response, so we wait for 0.5 seconds to handle any potential errors that may occur.
// The potential errors include "show_fw", "toofast", and "show_offline_limit".
if err = p.SyncSendWithTimeout(cb, 500*time.Millisecond, "msg", username, text, "\r\n"); err == ErrTimeout {
return nil
}
// Notifies the PM server that the client has just been active.
p.WentActive()
return
}

Inconsistent callback design between the SyncSend* methods and the Range method of *SyncMap

The callback should return false if a correct frame is acquired, and true otherwise.

chadango/group.go

Lines 243 to 244 in 20a1771

// The `callback` should return `true` if a correct frame is acquired, and `false` otherwise.
func (g *Group) SyncSendWithTimeout(callback func(string) bool, timeout time.Duration, args ...string) (err error) {

chadango/private.go

Lines 217 to 218 in 20a1771

// The `callback` should return `true` if a correct frame is acquired, and `false` otherwise.
func (p *Private) SyncSendWithTimeout(callback func(string) bool, timeout time.Duration, args ...string) (err error) {

Just like the implementation in SyncMap.

chadango/syncmap.go

Lines 45 to 46 in 20a1771

// If the function returns false, the iteration stops.
func (sm *SyncMap[K, V]) Range(fun func(K, V) bool) {

chadango/syncmap.go

Lines 160 to 161 in 20a1771

// If the function returns false, the iteration stops.
func (sm *OrderedSyncMap[K, V]) Range(fun func(K, V) bool) {

chadango/syncmap.go

Lines 172 to 173 in 20a1771

// If the function returns false, the iteration stops.
func (sm *OrderedSyncMap[K, V]) RangeReversed(fun func(K, V) bool) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.