adding persian language

translating tg bot to persian
This commit is contained in:
AmirAbbas Vafaee 2023-02-20 17:06:56 +03:30 committed by GitHub
parent d4c8b926d3
commit b19c917a83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,22 +34,22 @@ func (j *StatsNotifyJob) SendMsgToTgbot(msg string) {
//Telegram bot basic info //Telegram bot basic info
tgBottoken, err := j.settingService.GetTgBotToken() tgBottoken, err := j.settingService.GetTgBotToken()
if err != nil || tgBottoken == "" { if err != nil || tgBottoken == "" {
logger.Warning("sendMsgToTgbot failed,GetTgBotToken fail:", err) logger.Warning("ارسال پیام به ربات ناموفق بود, دریافت توکن ربات ناموفق بود:", err)
return return
} }
tgBotid, err := j.settingService.GetTgBotChatId() tgBotid, err := j.settingService.GetTgBotChatId()
if err != nil { if err != nil {
logger.Warning("sendMsgToTgbot failed,GetTgBotChatId fail:", err) logger.Warning("ارسال پیام به ربات ناموفق بود, دریافت توکن ربات ناموفق بود:", err)
return return
} }
bot, err := tgbotapi.NewBotAPI(tgBottoken) bot, err := tgbotapi.NewBotAPI(tgBottoken)
if err != nil { if err != nil {
fmt.Println("get tgbot error:", err) fmt.Println("ارور اتصال به ربات:", err)
return return
} }
bot.Debug = true bot.Debug = true
fmt.Printf("Authorized on account %s", bot.Self.UserName) fmt.Printf("اهراز شده بر روی اکانت %s", bot.Self.UserName)
info := tgbotapi.NewMessage(int64(tgBotid), msg) info := tgbotapi.NewMessage(int64(tgBotid), msg)
//msg.ReplyToMessageID = int(tgBotid) //msg.ReplyToMessageID = int(tgBotid)
bot.Send(info) bot.Send(info)
@ -64,10 +64,10 @@ func (j *StatsNotifyJob) Run() {
//get hostname //get hostname
name, err := os.Hostname() name, err := os.Hostname()
if err != nil { if err != nil {
fmt.Println("get hostname error:", err) fmt.Println("ارور اتصال به هاست:", err)
return return
} }
info = fmt.Sprintf("Hostname:%s\r\n", name) info = fmt.Sprintf("هاست:%s\r\n", name)
//get ip address //get ip address
var ip string var ip string
netInterfaces, err := net.Interfaces() netInterfaces, err := net.Interfaces()
@ -104,11 +104,11 @@ func (j *StatsNotifyJob) Run() {
// NOTE:If there no any sessions here,need to notify here // NOTE:If there no any sessions here,need to notify here
// TODO:Sub-node push, automatic conversion format // TODO:Sub-node push, automatic conversion format
for _, inbound := range inbouds { for _, inbound := range inbouds {
info += fmt.Sprintf("Node name:%s\r\nPort:%d\r\nUpload↑:%s\r\nDownload↓:%s\r\nTotal:%s\r\n", inbound.Remark, inbound.Port, common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down), common.FormatTraffic((inbound.Up + inbound.Down))) info += fmt.Sprintf("نام کاربری:%s\r\nپورت:%d\r\nآپلود↑:%s\r\nدانلود↓:%s\r\nمجموع:%s\r\n", inbound.Remark, inbound.Port, common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down), common.FormatTraffic((inbound.Up + inbound.Down)))
if inbound.ExpiryTime == 0 { if inbound.ExpiryTime == 0 {
info += fmt.Sprintf("Expire date:unlimited\r\n \r\n") info += fmt.Sprintf("تاریخ انقضاء::نامحدود\r\n \r\n")
} else { } else {
info += fmt.Sprintf("Expire date:%s\r\n \r\n", time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05")) info += fmt.Sprintf("تاریخ انقضاء:%s\r\n \r\n", time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05"))
} }
} }
j.SendMsgToTgbot(info) j.SendMsgToTgbot(info)
@ -116,7 +116,7 @@ func (j *StatsNotifyJob) Run() {
func (j *StatsNotifyJob) UserLoginNotify(username string, ip string, time string, status LoginStatus) { func (j *StatsNotifyJob) UserLoginNotify(username string, ip string, time string, status LoginStatus) {
if username == "" || ip == "" || time == "" { if username == "" || ip == "" || time == "" {
logger.Warning("UserLoginNotify failed,invalid info") logger.Warning("اتصال به پنا ناموفق بود، مشخصات نادرست")
return return
} }
var msg string var msg string
@ -127,31 +127,31 @@ func (j *StatsNotifyJob) UserLoginNotify(username string, ip string, time string
return return
} }
if status == LoginSuccess { if status == LoginSuccess {
msg = fmt.Sprintf("Successfully logged-in to the panel\r\nHostname:%s\r\n", name) msg = fmt.Sprintf("با موفقیت به پنل وارد شدید\r\nHostname:%s\r\n", name)
} else if status == LoginFail { } else if status == LoginFail {
msg = fmt.Sprintf("Login to the panel was unsuccessful\r\nHostname:%s\r\n", name) msg = fmt.Sprintf("اتصال به پنل ناموفق بود\r\nHostname:%s\r\n", name)
} }
msg += fmt.Sprintf("Time:%s\r\n", time) msg += fmt.Sprintf("مدت زمان:%s\r\n", time)
msg += fmt.Sprintf("Username:%s\r\n", username) msg += fmt.Sprintf("نام کاربری:%s\r\n", username)
msg += fmt.Sprintf("IP:%s\r\n", ip) msg += fmt.Sprintf("IP:%s\r\n", ip)
j.SendMsgToTgbot(msg) j.SendMsgToTgbot(msg)
} }
var numericKeyboard = tgbotapi.NewInlineKeyboardMarkup( var numericKeyboard = tgbotapi.NewInlineKeyboardMarkup(
tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardRow(
tgbotapi.NewInlineKeyboardButtonData("Get Usage", "get_usage"), tgbotapi.NewInlineKeyboardButtonData("وضعیت کاربری", "وضعیت کاربری"),
), ),
) )
func (j *StatsNotifyJob) OnReceive() *StatsNotifyJob { func (j *StatsNotifyJob) OnReceive() *StatsNotifyJob {
tgBottoken, err := j.settingService.GetTgBotToken() tgBottoken, err := j.settingService.GetTgBotToken()
if err != nil || tgBottoken == "" { if err != nil || tgBottoken == "" {
logger.Warning("sendMsgToTgbot failed,GetTgBotToken fail:", err) logger.Warning("ارسال پیام به ربات ناموفق بود, دریافت توکن ربات ناموفق بود:", err)
return j return j
} }
bot, err := tgbotapi.NewBotAPI(tgBottoken) bot, err := tgbotapi.NewBotAPI(tgBottoken)
if err != nil { if err != nil {
fmt.Println("get tgbot error:", err) fmt.Println("ارور اتصال به ربات:", err)
return j return j
} }
bot.Debug = false bot.Debug = false
@ -175,8 +175,8 @@ func (j *StatsNotifyJob) OnReceive() *StatsNotifyJob {
msg := tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID, "") msg := tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID, "")
switch update.CallbackQuery.Data { switch update.CallbackQuery.Data {
case "get_usage": case "وضعیت کاربری":
msg.Text = "for get your usage send command like this : \n <code>/usage uuid | id</code> \n example : <code>/usage fc3239ed-8f3b-4151-ff51-b183d5182142</code>" msg.Text = " برای دریافت وضعیت کاربری، دستوری به شکل زیر ارسال کنید: : \n <code>/usage uuid | id</code> \n مثال : <code>/usage fc3239ed-8f3b-4151-ff51-b183d5182142</code>"
msg.ParseMode = "HTML" msg.ParseMode = "HTML"
} }
if _, err := bot.Send(msg); err != nil { if _, err := bot.Send(msg); err != nil {
@ -198,19 +198,19 @@ func (j *StatsNotifyJob) OnReceive() *StatsNotifyJob {
// Extract the command from the Message. // Extract the command from the Message.
switch update.Message.Command() { switch update.Message.Command() {
case "help": case "help":
msg.Text = "What you need?" msg.Text = "چه کمکی از دست من برمیاد؟"
msg.ReplyMarkup = numericKeyboard msg.ReplyMarkup = numericKeyboard
case "start": case "start":
msg.Text = "Hi :) \n What you need?" msg.Text = "سلام :) \n چه کمکی از دست من برمیاد؟"
msg.ReplyMarkup = numericKeyboard msg.ReplyMarkup = numericKeyboard
case "status": case "status":
msg.Text = "bot is ok." msg.Text = "ربات حالش خوبه، تو خوبی؟ :)"
case "usage": case "usage":
msg.Text = j.getClientUsage(update.Message.CommandArguments()) msg.Text = j.getClientUsage(update.Message.CommandArguments())
default: default:
msg.Text = "I don't know that command, /help" msg.Text = "این دستور شناخته شده نیست :(, /help"
msg.ReplyMarkup = numericKeyboard msg.ReplyMarkup = numericKeyboard
} }
@ -226,21 +226,21 @@ func (j *StatsNotifyJob) getClientUsage(id string) string {
traffic, err := j.inboundService.GetClientTrafficById(id) traffic, err := j.inboundService.GetClientTrafficById(id)
if err != nil { if err != nil {
logger.Warning(err) logger.Warning(err)
return "something wrong!" return "یه اشتباهی رخ داد!"
} }
expiryTime := "" expiryTime := ""
if traffic.ExpiryTime == 0 { if traffic.ExpiryTime == 0 {
expiryTime = fmt.Sprintf("unlimited") expiryTime = fmt.Sprintf("نامحدود")
} else { } else {
expiryTime = fmt.Sprintf("%s", time.Unix((traffic.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05")) expiryTime = fmt.Sprintf("%s", time.Unix((traffic.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05"))
} }
total := "" total := ""
if traffic.Total == 0 { if traffic.Total == 0 {
total = fmt.Sprintf("unlimited") total = fmt.Sprintf("نامحدود")
} else { } else {
total = fmt.Sprintf("%s", common.FormatTraffic((traffic.Total))) total = fmt.Sprintf("%s", common.FormatTraffic((traffic.Total)))
} }
output := fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n", output := fmt.Sprintf("💡 فعال: %t\r\n📧 نام کاربری: %s\r\n🔼 آپلود↑: %s\r\n🔽 دانلود↓: %s\r\n🔄 مجموع: %s / %s\r\n📅 تاریخ انقضاء: %s\r\n",
traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)), traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)),
total, expiryTime) total, expiryTime)