Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
d6125cd9
Commit
d6125cd9
authored
Oct 09, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move logging extensions for bot to BotHelper.kt
parent
71316006
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
36 deletions
+41
-36
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotHelper.kt
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotHelper.kt
+41
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLogger.kt
...e/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLogger.kt
+0
-35
No files found.
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotHelper.kt
View file @
d6125cd9
...
...
@@ -3,8 +3,14 @@ package net.mamoe.mirai
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.network.protocol.tim.packet.ClientPacket
import
net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import
net.mamoe.mirai.network.protocol.tim.packet.goto
import
net.mamoe.mirai.network.protocol.tim.packet.login.LoginState
import
net.mamoe.mirai.utils.ContactList
import
net.mamoe.mirai.utils.LoggerTextFormat
import
net.mamoe.mirai.utils.toUHexString
import
java.text.SimpleDateFormat
import
java.util.*
/**
* The mirror of functions in inner classes of [Bot]
...
...
@@ -30,4 +36,38 @@ suspend fun Bot.sendPacket(packet: ClientPacket) = this.network.socket.sendPacke
suspend
fun
Bot
.
login
():
LoginState
=
this
.
network
.
login
()
//BotAccount
val
Bot
.
qqNumber
:
Long
get
()
=
this
.
account
.
qqNumber
\ No newline at end of file
val
Bot
.
qqNumber
:
Long
get
()
=
this
.
account
.
qqNumber
//logging
fun
Bot
.
log
(
o
:
Any
?)
=
info
(
o
)
fun
Bot
.
println
(
o
:
Any
?)
=
info
(
o
)
fun
Bot
.
info
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
RESET
)
fun
Bot
.
error
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
RED
)
fun
Bot
.
notice
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
LIGHT_BLUE
)
fun
Bot
.
purple
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
PURPLE
)
fun
Bot
.
cyan
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
LIGHT_CYAN
)
fun
Bot
.
green
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
GREEN
)
fun
Bot
.
debug
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
YELLOW
)
fun
Bot
.
debugPacket
(
packet
:
ServerPacket
)
{
debug
(
"Packet=$packet"
)
debug
(
"Packet size="
+
packet
.
input
.
goto
(
0
).
readAllBytes
().
size
)
debug
(
"Packet data="
+
packet
.
input
.
goto
(
0
).
readAllBytes
().
toUHexString
())
}
private
fun
print
(
bot
:
Bot
,
value
:
String
?,
color
:
LoggerTextFormat
=
LoggerTextFormat
.
WHITE
)
{
val
s
=
SimpleDateFormat
(
"MM-dd HH:mm:ss"
).
format
(
Date
())
kotlin
.
io
.
println
(
"$color[Mirai] $s #R${bot.id}: $value"
)
}
private
fun
print
(
value
:
String
?,
color
:
LoggerTextFormat
=
LoggerTextFormat
.
WHITE
)
{
val
s
=
SimpleDateFormat
(
"MM-dd HH:mm:ss"
).
format
(
Date
())
kotlin
.
io
.
println
(
"$color[Mirai] $s : $value"
)
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/MiraiLogger.kt
View file @
d6125cd9
package
net.mamoe.mirai.utils
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import
net.mamoe.mirai.network.protocol.tim.packet.goto
import
java.text.SimpleDateFormat
import
java.util.*
...
...
@@ -60,36 +57,4 @@ open class Console(
println
(
"$color$identity $s : $value"
)
}
}
fun
Bot
.
log
(
o
:
Any
?)
=
info
(
o
)
fun
Bot
.
println
(
o
:
Any
?)
=
info
(
o
)
fun
Bot
.
info
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
RESET
)
fun
Bot
.
error
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
RED
)
fun
Bot
.
notice
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
LIGHT_BLUE
)
fun
Bot
.
purple
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
PURPLE
)
fun
Bot
.
cyan
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
LIGHT_CYAN
)
fun
Bot
.
green
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
GREEN
)
fun
Bot
.
debug
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
YELLOW
)
fun
Bot
.
debugPacket
(
packet
:
ServerPacket
)
{
debug
(
"Packet=$packet"
)
debug
(
"Packet size="
+
packet
.
input
.
goto
(
0
).
readAllBytes
().
size
)
debug
(
"Packet data="
+
packet
.
input
.
goto
(
0
).
readAllBytes
().
toUHexString
())
}
private
fun
print
(
bot
:
Bot
,
value
:
String
?,
color
:
LoggerTextFormat
=
LoggerTextFormat
.
WHITE
)
{
val
s
=
SimpleDateFormat
(
"MM-dd HH:mm:ss"
).
format
(
Date
())
kotlin
.
io
.
println
(
"$color[Mirai] $s #R${bot.id}: $value"
)
}
private
fun
print
(
value
:
String
?,
color
:
LoggerTextFormat
=
LoggerTextFormat
.
WHITE
)
{
val
s
=
SimpleDateFormat
(
"MM-dd HH:mm:ss"
).
format
(
Date
())
kotlin
.
io
.
println
(
"$color[Mirai] $s : $value"
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment