Example #1
0
func (m *Random) Chat(msg xmpp.Chat) {
	if len(msg.Text) == 0 || !msg.Stamp.IsZero() {
		return
	}
	if msg.Type == "chat" {
		if m.Option["chat"] {
			if msg.Text == m.bot.GetCmdString("f**k") {
				m.bot.ReplyAuto(msg, m.FuckList[rand.Intn(len(m.FuckList))])
			} else {
				m.bot.ReplyAuto(msg, m.RandomList[rand.Intn(len(m.RandomList))])
			}
		}
	} else if msg.Type == "groupchat" {
		if m.Option["room"] {
			//忽略bot自己发送的消息
			if m.bot.SentThis(msg) || m.bot.BlockRemote(msg) {
				return
			}
			if msg.Text == m.bot.GetCmdString("f**k") {
				roomid, nick := utils.SplitJID(msg.Remote)
				m.bot.SendPub(roomid, nick+": "+m.FuckList[rand.Intn(len(m.FuckList))])
			}
			if ok, _ := m.bot.Called(msg); ok {
				roomid, _ := utils.SplitJID(msg.Remote)
				m.bot.SendPub(roomid, m.RandomList[rand.Intn(len(m.RandomList))])
			}
		}
	}
}
Example #2
0
func (m *Url) Chat(msg xmpp.Chat) {
	if len(msg.Text) == 0 || !msg.Stamp.IsZero() {
		return
	}

	if msg.Type == "chat" {
		if m.Option["chat"].(bool) {
			if m.bot.SentThis(msg) {
				return
			}
			text := m.GetHelper(msg.Text)
			if text != "" {
				m.bot.ReplyAuto(msg, fmt.Sprintf("<p>%s</p>", text))
			}
		}
	} else if msg.Type == "groupchat" {
		if m.Option["room"].(bool) {
			//忽略bot自己发送的消息
			if m.bot.SentThis(msg) || m.bot.BlockRemote(msg) {
				return
			}
			text := m.GetHelper(msg.Text)
			if text != "" {
				roomid, nick := utils.SplitJID(msg.Remote)
				m.bot.SendPub(roomid, fmt.Sprintf("<p>%s %s</p>", nick, text))
			}
		}
	}
}
Example #3
0
func (m *Admin) bot_unsubscribe(cmd string, msg xmpp.Chat) {
	tokens := strings.SplitN(cmd, " ", 2)
	if len(tokens) == 2 && strings.Contains(tokens[1], "@") {
		if !m.IsFriendID(tokens[1]) {
			m.bot.ReplyAuto(msg, tokens[1]+"不是好友,不需要删除!")
			return
		}
		jid, _ := utils.SplitJID(msg.Remote)
		if tokens[1] == jid {
			m.bot.ReplyAuto(msg, tokens[1]+"是你的id, 不支持这个操作!")
			return
		}

		if m.IsSysAdminID(tokens[1]) {
			m.bot.ReplyAuto(msg, "不允许删除超级管理员帐号 "+tokens[1]+"!")
			return
		}
		m.Friends = utils.ListDelete(m.Friends, tokens[1])
		m.bot.RevokeSubscription(tokens[1])
		if m.IsAdminID(tokens[1]) {
			m.admins = utils.ListDelete(m.admins, tokens[1])
			m.bot.ReplyAuto(msg, "将管理员帐号 "+tokens[1]+" 从好友中删除!")
		} else {
			m.bot.ReplyAuto(msg, "将帐号 "+tokens[1]+" 从好友中删除!")
		}
	}
}
Example #4
0
func (m *Tuling) Chat(msg xmpp.Chat) {
	if len(msg.Text) == 0 || !msg.Stamp.IsZero() {
		return
	}

	//忽略命令消息
	if m.bot.IsCmd(msg.Text) {
		return
	}

	if msg.Type == "chat" {
		if m.Option["chat"] {
			m.bot.ReplyAuto(msg, m.GetAnswer(msg.Text, utils.GetMd5(msg.Remote)))
		}
	} else if msg.Type == "groupchat" {
		if m.Option["room"] {
			//忽略bot自己发送的消息
			if m.bot.SentThis(msg) || m.bot.BlockRemote(msg) {
				return
			}
			if ok, message := m.bot.Called(msg); ok {
				roomid, _ := utils.SplitJID(msg.Remote)
				m.bot.SendPub(roomid, m.GetAnswer(message, utils.GetMd5(msg.Remote)))
			}
		}
	}
}
Example #5
0
func (b *Bot) IsRoomID(jid string) bool {
	roomid, _ := utils.SplitJID(jid)
	for _, v := range b.admin.GetRooms() {
		if roomid == v.JID {
			return true
		}
	}
	return false
}
Example #6
0
func (m *Admin) IsFriendID(jid string) bool {
	u, _ := utils.SplitJID(jid)
	for _, friend := range m.Friends {
		if u == friend {
			return true
		}
	}
	return false
}
Example #7
0
func (m *Admin) IsSysAdminID(jid string) bool {
	u, _ := utils.SplitJID(jid)
	for _, admin := range m.cfg.Setup.Admin {
		if u == admin {
			return true
		}
	}
	return false
}
Example #8
0
func (m *Admin) admin_del(cmd string, msg xmpp.Chat) {
	tokens := strings.SplitN(cmd, " ", 2)
	jid, _ := utils.SplitJID(msg.Remote)
	if m.IsAdminID(tokens[1]) && tokens[1] != jid {
		m.admins = utils.ListDelete(m.admins, tokens[1])
		m.bot.SendAuto(tokens[1], jid+" 临时取消了您的管理员身份!")
	} else {
		m.bot.ReplyAuto(msg, "不能取消 "+tokens[1]+" 的管理员身份!")
	}
}
Example #9
0
// 此人在聊天中被忽略了吗?
func (b *Bot) BlockRemote(msg xmpp.Chat) bool {
	if msg.Type == "groupchat" {
		for _, v := range b.admin.GetRooms() {
			roomid, nick := utils.SplitJID(msg.Remote)
			if roomid == v.JID && v.IsBlocked(nick) {
				return true
			}
		}
	}
	return false
}
Example #10
0
// 回复好友消息,或聊天室公共消息
func (b *Bot) ReplyPub(recv xmpp.Chat, text string) {
	if recv.Type == "groupchat" {
		roomid, _ := utils.SplitJID(recv.Remote)
		if strings.Contains(text, "<a href") || strings.Contains(text, "<img") {
			b.SendHtml(xmpp.Chat{Remote: roomid, Type: recv.Type, Text: text})
		} else {
			b.client.Send(xmpp.Chat{Remote: roomid, Type: recv.Type, Text: text})
		}
	} else {
		b.ReplyAuto(recv, text)
	}
}
Example #11
0
func (m *Logger) LogInsert(msg xmpp.Chat) (err error) {
	jid, nick := utils.SplitJID(msg.Remote)
	log := &ChatLogger{JID: jid, Nick: nick, Text: msg.Text}

	if strings.Contains(msg.Text, "<img") {
		log.IsImage = true
	}
	if msg.Type == "groupchat" {
		log.IsRoom = true
	}
	_, err = m.x.InsertOne(log)
	return
}
Example #12
0
// 消息是由bot自己发出的吗?
func (b *Bot) SentThis(msg xmpp.Chat) bool {

	if msg.Type == "chat" {
		if id, res := utils.SplitJID(msg.Remote); id == b.cfg.Account.Username && res == b.cfg.Account.Resource {
			return true
		}
	} else if msg.Type == "groupchat" {
		for _, v := range b.admin.GetRooms() {
			if msg.Remote == v.JID+"/"+v.Nickname {
				return true
			}
		}
	}
	return false
}
Example #13
0
func (m *Admin) admin_add(cmd string, msg xmpp.Chat) {
	tokens := strings.SplitN(cmd, " ", 2)
	if len(tokens) == 2 && strings.Contains(tokens[1], "@") {
		if m.IsAdminID(tokens[1]) {
			m.bot.ReplyAuto(msg, tokens[1]+" 已是管理员用户,不需再次增加!")
		} else {
			if !m.IsFriendID(tokens[1]) {
				m.bot.RequestSubscription(tokens[1])
			}
			m.admins = append(m.admins, tokens[1])
			m.bot.ReplyAuto(msg, "您已添加 "+tokens[1]+"为管理员!")
			jid, _ := utils.SplitJID(msg.Remote)
			m.bot.SendAuto(tokens[1], jid+" 添加您为临时管理员!")
		}
	}
}