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
900040f9
Commit
900040f9
authored
Sep 29, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved logger
parent
312fb437
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
40 deletions
+77
-40
mirai-console/src/main/java/net/mamoe/mirai/MiraiServer.java
mirai-console/src/main/java/net/mamoe/mirai/MiraiServer.java
+3
-6
mirai-core/src/main/java/net/mamoe/mirai/Bot.java
mirai-core/src/main/java/net/mamoe/mirai/Bot.java
+9
-1
mirai-core/src/main/java/net/mamoe/mirai/Mirai.kt
mirai-core/src/main/java/net/mamoe/mirai/Mirai.kt
+21
-0
mirai-core/src/main/java/net/mamoe/mirai/network/BotNetworkHandlerImpl.kt
...ain/java/net/mamoe/mirai/network/BotNetworkHandlerImpl.kt
+1
-1
mirai-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt
...i-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt
+39
-30
mirai-core/src/test/java/BadQQFilter.kt
mirai-core/src/test/java/BadQQFilter.kt
+2
-1
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
+2
-1
No files found.
mirai-console/src/main/java/net/mamoe/mirai/MiraiServer.java
View file @
900040f9
...
...
@@ -6,10 +6,7 @@ import net.mamoe.mirai.event.events.server.ServerDisabledEvent;
import
net.mamoe.mirai.event.events.server.ServerEnabledEvent
;
import
net.mamoe.mirai.network.packet.login.LoginState
;
import
net.mamoe.mirai.task.MiraiTaskManager
;
import
net.mamoe.mirai.utils.BotAccount
;
import
net.mamoe.mirai.utils.LoggerTextFormat
;
import
net.mamoe.mirai.utils.MiraiLogger
;
import
net.mamoe.mirai.utils.MiraiLoggerKt
;
import
net.mamoe.mirai.utils.*
;
import
net.mamoe.mirai.utils.config.MiraiConfig
;
import
net.mamoe.mirai.utils.setting.MiraiSettingListSection
;
import
net.mamoe.mirai.utils.setting.MiraiSettingMapSection
;
...
...
@@ -78,7 +75,7 @@ public final class MiraiServer {
this
.
parentFolder
=
new
File
(
System
.
getProperty
(
"user.dir"
));
this
.
unix
=
!
System
.
getProperties
().
getProperty
(
"os.name"
).
toUpperCase
().
contains
(
"WINDOWS"
);
this
.
logger
=
MiraiLogger
.
INSTANCE
;
this
.
logger
=
MiraiLogger
.
Companion
;
this
.
eventManager
=
MiraiEventManager
.
getInstance
();
this
.
taskManager
=
MiraiTaskManager
.
getInstance
();
...
...
@@ -201,7 +198,7 @@ public final class MiraiServer {
private
Bot
getAvailableBot
()
throws
ExecutionException
,
InterruptedException
{
for
(
String
it
:
qqList
.
split
(
"\n"
))
{
var
strings
=
it
.
split
(
"----"
);
var
bot
=
new
Bot
(
new
BotAccount
(
Long
.
parseLong
(
strings
[
0
]),
strings
[
1
]));
var
bot
=
new
Bot
(
new
BotAccount
(
Long
.
parseLong
(
strings
[
0
]),
strings
[
1
])
,
new
Console
()
);
if
(
bot
.
network
.
tryLogin
(
200
).
get
()
==
LoginState
.
SUCCESS
)
{
MiraiLoggerKt
.
success
(
bot
,
"Login succeed"
);
...
...
mirai-core/src/main/java/net/mamoe/mirai/Bot.java
View file @
900040f9
...
...
@@ -6,6 +6,7 @@ import net.mamoe.mirai.network.BotNetworkHandler;
import
net.mamoe.mirai.network.BotNetworkHandlerImpl
;
import
net.mamoe.mirai.utils.BotAccount
;
import
net.mamoe.mirai.utils.ContactList
;
import
net.mamoe.mirai.utils.MiraiLogger
;
import
org.jetbrains.annotations.NotNull
;
import
java.io.Closeable
;
...
...
@@ -57,6 +58,8 @@ public final class Bot implements Closeable {
public
final
BotNetworkHandler
network
;
public
final
MiraiLogger
logger
;
@Override
public
String
toString
()
{
return
String
.
format
(
"Bot{id=%d,qq=%d}"
,
id
,
this
.
account
.
getQqNumber
());
...
...
@@ -94,9 +97,14 @@ public final class Bot implements Closeable {
}
}
public
Bot
(
@NotNull
BotAccount
account
)
{
public
Bot
(
@NotNull
BotAccount
account
,
@NotNull
MiraiLogger
logger
)
{
Objects
.
requireNonNull
(
account
);
this
.
account
=
account
;
this
.
logger
=
Objects
.
requireNonNull
(
logger
);
this
.
logger
.
setIdentity
(
"Bot"
+
this
.
id
+
"("
+
this
.
account
.
getQqNumber
()
+
")"
);
this
.
network
=
new
BotNetworkHandlerImpl
(
this
);
}
...
...
mirai-core/src/main/java/net/mamoe/mirai/Mirai.kt
0 → 100644
View file @
900040f9
package
net.mamoe.mirai
import
java.io.File
/**
* @author Him188moe
*/
object
Mirai
{
val
VERSION
:
String
get
()
=
internal
.
version
val
WORKING_DIRECTORY
:
File
get
()
=
internal
.
workingDirectory
internal
lateinit
var
internal
:
MiraiInternal
internal
abstract
class
MiraiInternal
{
abstract
val
workingDirectory
:
File
abstract
val
version
:
String
}
}
mirai-core/src/main/java/net/mamoe/mirai/network/BotNetworkHandlerImpl.kt
View file @
900040f9
...
...
@@ -223,7 +223,7 @@ internal class BotNetworkHandlerImpl(private val bot: Bot) : BotNetworkHandler {
withContext
(
Dispatchers
.
IO
)
{
socket
!!
.
send
(
DatagramPacket
(
data
,
data
.
size
))
}
bot
.
cyan
L
(
"Packet sent: $packet"
)
bot
.
cyan
(
"Packet sent: $packet"
)
PacketSentEvent
(
bot
,
packet
).
broadcast
()
}
catch
(
e
:
Throwable
)
{
...
...
mirai-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt
View file @
900040f9
...
...
@@ -6,38 +6,56 @@ import net.mamoe.mirai.network.packet.goto
import
java.text.SimpleDateFormat
import
java.util.*
/**
* used to replace old logger
*
* @author Him188moe
* @author NaturalHG
*/
object
MiraiLogger
{
fun
log
(
o
:
Any
?)
=
info
(
o
)
fun
println
(
o
:
Any
?)
=
info
(
o
)
fun
info
(
o
:
Any
?)
=
this
.
print
(
o
.
toString
(),
LoggerTextFormat
.
RESET
)
interface
MiraiLogger
{
companion
object
:
Console
(
"[TOP Level]"
)
var
identity
:
String
fun
info
(
any
:
Any
?)
=
log
(
any
)
fun
log
(
any
:
Any
?)
fun
error
(
any
:
Any
?)
fun
debug
(
any
:
Any
?)
fun
error
(
o
:
Any
?)
=
this
.
print
(
o
.
toString
(),
LoggerTextFormat
.
RED
)
fun
cyan
(
any
:
Any
?
)
fun
notice
(
o
:
Any
?)
=
this
.
print
(
o
.
toString
(),
LoggerTextFormat
.
LIGHT_BLUE
)
fun
purple
(
any
:
Any
?
)
fun
success
(
o
:
Any
?)
=
this
.
print
(
o
.
toString
(),
LoggerTextFormat
.
GREEN
)
fun
green
(
any
:
Any
?
)
fun
debug
(
o
:
Any
?)
=
this
.
print
(
o
.
toString
(),
LoggerTextFormat
.
YELLOW
)
fun
blue
(
any
:
Any
?)
}
val
DEBUGGING
:
Boolean
by
lazy
{
//avoid inspections
true
}
fun
catching
(
e
:
Throwable
)
{
e
.
printStackTrace
()
/*
this.print(e.message)
this.print(e.localizedMessage)
this.print(e.cause.toString())*/
open
class
Console
(
override
var
identity
:
String
=
"[Unknown]"
)
:
MiraiLogger
{
override
fun
green
(
any
:
Any
?)
=
print
(
any
.
toString
(),
LoggerTextFormat
.
GREEN
)
override
fun
purple
(
any
:
Any
?)
=
print
(
any
.
toString
(),
LoggerTextFormat
.
LIGHT_PURPLE
)
override
fun
blue
(
any
:
Any
?)
=
print
(
any
.
toString
(),
LoggerTextFormat
.
BLUE
)
override
fun
cyan
(
any
:
Any
?)
=
print
(
any
.
toString
(),
LoggerTextFormat
.
LIGHT_CYAN
)
override
fun
error
(
any
:
Any
?)
=
print
(
any
.
toString
(),
LoggerTextFormat
.
RED
)
override
fun
log
(
any
:
Any
?)
=
print
(
any
.
toString
(),
LoggerTextFormat
.
LIGHT_GRAY
)
override
fun
debug
(
any
:
Any
?)
{
if
(
DEBUGGING
)
{
print
(
any
.
toString
(),
LoggerTextFormat
.
YELLOW
)
}
}
@Synchronized
private
fun
print
(
value
:
String
?,
color
:
LoggerTextFormat
=
LoggerTextFormat
.
WHITE
)
{
fun
print
(
value
:
String
?,
color
:
LoggerTextFormat
=
LoggerTextFormat
.
YELLOW
)
{
val
s
=
SimpleDateFormat
(
"MM-dd HH:mm:ss"
).
format
(
Date
())
kotlin
.
io
.
println
(
"$color[Mirai] $s : $value"
)
println
(
"$color$identity $s : $value"
)
}
}
...
...
@@ -51,7 +69,7 @@ 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
L
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
LIGHT_CYAN
)
fun
Bot
.
cyan
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
LIGHT_CYAN
)
fun
Bot
.
success
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
GREEN
)
fun
Bot
.
debug
(
o
:
Any
?)
=
print
(
this
,
o
.
toString
(),
LoggerTextFormat
.
YELLOW
)
...
...
@@ -69,17 +87,8 @@ private fun print(bot: Bot, value: String?, color: LoggerTextFormat = LoggerText
kotlin
.
io
.
println
(
"$color[Mirai] $s #R${bot.id}: $value"
)
}
@Synchronized
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"
)
}
fun
Any
.
logInfo
()
=
MiraiLogger
.
info
(
this
)
fun
Any
.
logDebug
()
=
MiraiLogger
.
debug
(
this
)
fun
Any
.
logError
()
=
MiraiLogger
.
error
(
this
)
fun
Any
.
logNotice
()
=
MiraiLogger
.
notice
(
this
)
\ No newline at end of file
}
\ No newline at end of file
mirai-core/src/test/java/BadQQFilter.kt
View file @
900040f9
...
...
@@ -3,6 +3,7 @@ import kotlinx.coroutines.launch
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.network.packet.login.LoginState
import
net.mamoe.mirai.utils.BotAccount
import
net.mamoe.mirai.utils.Console
import
java.util.*
/**
...
...
@@ -74,7 +75,7 @@ fun main() {
return
@
let
password
.
substring
(
0
,
password
.
length
-
1
)
}
return
@
let
password
}))
})
,
Console
()
)
bot
.
network
.
tryLogin
().
whenComplete
{
state
,
_
->
if
(!(
state
==
LoginState
.
BLOCKED
||
state
==
LoginState
.
DEVICE_LOCK
||
state
==
LoginState
.
WRONG_PASSWORD
))
{
...
...
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
View file @
900040f9
...
...
@@ -9,6 +9,7 @@ import net.mamoe.mirai.message.defaults.Image
import
net.mamoe.mirai.message.defaults.PlainText
import
net.mamoe.mirai.network.packet.login.LoginState
import
net.mamoe.mirai.utils.BotAccount
import
net.mamoe.mirai.utils.Console
/**
* @author Him188moe
...
...
@@ -17,7 +18,7 @@ fun main() {
val
bot
=
Bot
(
BotAccount
(
qqNumber
=
1683921395
,
password
=
"bb22222"
))
)
,
Console
()
)
bot
.
network
.
tryLogin
().
get
().
let
{
check
(
it
==
LoginState
.
SUCCESS
)
{
"Login failed: "
+
it
.
name
}
...
...
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