Exemplo n.º 1
0
// HandleCommand handles a /language command
func HandleCommand(bot *telebot.Bot, message telebot.Message, args []string) {
	sender := config.GetUserWithUID(message.Sender.ID)
	if len(args) > 0 {
		lang := GetLanguage(args[0])
		if lang == nil {
			bot.SendMessage(message.Chat, Translatef(sender, "lang.notfound", lang.Name), util.Markdown)
			return
		}

		if len(args) > 1 {
			user := config.GetUser(args[1])
			if user.UID != config.NilUser.UID && !sender.HasPermission(langChangeOtherPerm) {
				bot.SendMessage(message.Chat, Translatef(sender, "error.noperms", langChangeOtherPerm), util.Markdown)
				return
			}

			user.SetSetting("language", lang.Name)
			bot.SendMessage(message.Chat, Translatef(sender, "lang.changed.other", lang.Name, user.Name), util.Markdown)
		} else {
			sender.SetSetting("language", lang.Name)
			bot.SendMessage(message.Chat, Translatef(sender, "lang.changed", lang.Name), util.Markdown)
		}
	} else {
		bot.SendMessage(message.Chat, Translatef(sender, "lang.usage"), util.Markdown)
	}
}
Exemplo n.º 2
0
func sendSecondYear(day int, bot *telebot.Bot, message telebot.Message) {
	sender := config.GetUserWithUID(message.Sender.ID)
	bot.SendMessage(message.Chat,
		lang.Translatef(sender, "timetable.generic",
			secondyear[day][0].Subject, secondyear[day][1].Subject, secondyear[day][2].Subject, secondyear[day][3].Subject,
			util.DateToString(secondyear[day][0].Date))+"\n"+lang.Translatef(sender, "timetable.other", other[day].Subject),
		util.Markdown)
}
Exemplo n.º 3
0
// HandleCommand handles a /timetable command
func HandleCommand(bot *telebot.Bot, message telebot.Message, args []string) {
	sender := config.GetUserWithUID(message.Sender.ID)
	if util.Timestamp() > lastupdate+600 {
		bot.SendMessage(message.Chat, lang.Translatef(sender, "timetable.update"), util.Markdown)
		Update()
	}

	day := today
	year := sender.Year
	if len(args) == 1 {
		if util.CheckArgs(args[0], lang.Translate(sender, "timetable.year.first")) {
			year = 1
		} else if util.CheckArgs(args[0], lang.Translate(sender, "timetable.year.second")) {
			year = 2
		} else if util.CheckArgs(args[0], "update") {
			Update()
			bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.update.success"), util.Markdown)
		} else {
			dayNew, err := shift(day, args[0], 0, len(other))
			if err != nil {
				if err.Error() == "OOB" {
					bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.nodata"), util.Markdown)
				} else if err.Error() == "PARSEINT" {
					bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.usage"), util.Markdown)
				}
				return
			}
			day = dayNew
		}
	} else if len(args) == 2 {
		if util.CheckArgs(args[0], lang.Translate(sender, "timetable.year.first")) {
			year = 1
		} else if util.CheckArgs(args[0], lang.Translate(sender, "timetable.year.second")) {
			year = 2
		} else {
			bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.usage"), util.Markdown)
		}
		dayNew, err := shift(day, args[1], 0, len(other))
		if err != nil {
			if err.Error() == "OOB" {
				bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.nodata"), util.Markdown)
			} else if err.Error() == "PARSEINT" {
				bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.usage"), util.Markdown)
			}
			return
		}
		day = dayNew
	}

	if day < 0 || day >= len(other) {
		bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.nodata"), util.Markdown)
		return
	}

	if year == 1 {
		sendFirstYear(day, bot, message)
	} else if year == 2 {
		sendSecondYear(day, bot, message)
	} else {
		bot.SendMessage(message.Chat, lang.Translate(sender, "timetable.noyeargroup"), util.Markdown)
	}
}