MCPcopy Create free account
hub / github.com/chanify/chanify / makeTextContent

Method makeTextContent

core/sender.go:203–248  ·  view source on GitHub ↗
(msg *model.Message, text string, title string, copytext string, autocopy string, actions []string)

Source from the content-addressed store, hash-verified

201}
202
203func (c *Core) makeTextContent(msg *model.Message, text string, title string, copytext string, autocopy string, actions []string) (*model.Message, error) {
204 var fname string
205 if len(copytext) > 1000 {
206 return nil, ErrTooLargeContent
207 }
208 l := len(title) + len(text)
209 if len(actions) > 4 {
210 actions = actions[:4]
211 }
212 for _, act := range actions {
213 l += len(act)
214 }
215 if l < 2000 {
216 if len(actions) > 0 {
217 return c.makeActionContent(msg, text, title, actions)
218 }
219 return msg.TextContent(text, title, copytext, autocopy), nil
220 }
221 if !c.logic.CanFileStore() {
222 return nil, ErrTooLargeContent
223 }
224 txts := []string{}
225 if len(title) > 0 {
226 txts = append(txts, title)
227 fname = title
228 }
229 if len(text) > 0 {
230 txts = append(txts, text)
231 }
232 data := []byte(strings.Join(txts, "\n\n"))
233 path, err := c.logic.SaveFile("files", data)
234 if err != nil {
235 return nil, err
236 }
237 if len(title) > 100 {
238 fname = string([]rune(title)[:100])
239 title = fname + "⋯"
240 }
241 if len(fname) > 0 {
242 fname = strings.ReplaceAll(filepath.Base(fname), ".", "")
243 }
244 if len(fname) <= 0 {
245 fname = "text"
246 }
247 return msg.TextFileContent(path, fname+".txt", title, string([]rune(text)[:100])+"⋯", len(data), actions), nil
248}
249
250func (c *Core) makeActionContent(msg *model.Message, text string, title string, actions []string) (*model.Message, error) {
251 return msg.ActionContent(text, title, actions), nil

Callers 9

handleSenderMethod · 0.95
handlePostSenderMethod · 0.95
luaContextSendFunction · 0.80
TestTooLargeTextFunction · 0.80
TestTooLargeTextNoTitleFunction · 0.80
TestTooLargeTextFailedFunction · 0.80
TestSendActionFunction · 0.80
TestSendActionFailedFunction · 0.80

Calls 5

makeActionContentMethod · 0.95
TextContentMethod · 0.80
CanFileStoreMethod · 0.80
SaveFileMethod · 0.80
TextFileContentMethod · 0.80

Tested by 6

TestTooLargeTextFunction · 0.64
TestTooLargeTextNoTitleFunction · 0.64
TestTooLargeTextFailedFunction · 0.64
TestSendActionFunction · 0.64
TestSendActionFailedFunction · 0.64