传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg)
(ctx *zero.Ctx, welcome string)
| 713 | |
| 714 | // 传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg) |
| 715 | func welcometocq(ctx *zero.Ctx, welcome string) string { |
| 716 | uid := strconv.FormatInt(ctx.Event.UserID, 10) // 用户id |
| 717 | nickname := ctx.CardOrNickName(ctx.Event.UserID) // 用户昵称 |
| 718 | at := "[CQ:at,qq=" + uid + "]" // at用户 |
| 719 | avatar := "[CQ:image,file=" + "https://q4.qlogo.cn/g?b=qq&nk=" + uid + "&s=640]" // 用户头像 |
| 720 | gid := strconv.FormatInt(ctx.Event.GroupID, 10) // 群id |
| 721 | groupname := ctx.GetThisGroupInfo(true).Name // 群名 |
| 722 | cqstring := strings.ReplaceAll(welcome, "{at}", at) |
| 723 | cqstring = strings.ReplaceAll(cqstring, "{nickname}", nickname) |
| 724 | cqstring = strings.ReplaceAll(cqstring, "{avatar}", avatar) |
| 725 | cqstring = strings.ReplaceAll(cqstring, "{uid}", uid) |
| 726 | cqstring = strings.ReplaceAll(cqstring, "{gid}", gid) |
| 727 | cqstring = strings.ReplaceAll(cqstring, "{groupname}", groupname) |
| 728 | return cqstring |
| 729 | } |