Skip to content

Commit 80d4a98

Browse files
committed
FunkMan v0.3.0
- Moved images to funkpics directory - Changed ini sections - Added testfiles directory
1 parent fecde13 commit 80d4a98

23 files changed

+188
-61
lines changed

FunkMan.ini

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
#--------------------------------------------------------------------------------------
22
# FUNKMAN Config File
3+
# ===================
4+
# The config file consists of multiple section each starting with square brackets.
5+
6+
# [DEFAULT] This sections contains a parameter for debugging:
7+
8+
# [FUNKBOT] This section contains information about the Discord bot parmeters:
9+
# TOKEN: Is the secret (!) token of the bot.
10+
# CHANNELID_MAIN: The main channel ID used for all messages by default.
11+
# CHANNELID_RANGE: (Optional) Channel ID where RANGE messages are send to.
12+
# CHANNELID_AIRBOSS: (Optional) Channel ID where AIRBOSS messages are send to.
13+
#
14+
# [FUNKSOCK] This section contains information about the UDP socket:
15+
# PORT: UDP Port. Default is 10042.
16+
# HOST: Host name. Default is 127.0.0.1.
17+
#
18+
# [FUNKPLOT] This section contains information for plotting images.
19+
# IMAGEPATH: Directory where the necessary images are stored.
320
#--------------------------------------------------------------------------------------
421

5-
[FUNKMAN]
6-
TOKEN=MyBotToken!
7-
PORT=10042
8-
HOST=127.0.0.1
22+
[DEFAULT]
23+
DEBUGLEVEL=0
24+
25+
[FUNKBOT]
26+
TOKEN=YOUR_BOT_TOKEN_HERE
927
CHANNELID_MAIN=1011372894162526329
1028
CHANNELID_RANGE=1006216842509041786
1129
CHANNELID_AIRBOSS=1011372920968323155
12-
IMAGEPATH=./images/
30+
31+
[FUNKSOCK]
32+
PORT=10042
33+
HOST=127.0.0.1
34+
35+
[FUNKPLOT]
36+
IMAGEPATH=./funkpics/

funkman/funkbot/funkbot.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FunkBot(commands.Bot):
1616
API class wrapper for Discord based on discord.py.
1717
"""
1818

19-
def __init__(self, Token: str, ChannelID: int, Command_Prefix="!"):
19+
def __init__(self, Token: str, ChannelID: int, Command_Prefix="!", ImagePath="./funkpics/", DebugLevel=0):
2020

2121
# Init discord.Client superclass.
2222
super().__init__(Command_Prefix)
@@ -25,6 +25,9 @@ def __init__(self, Token: str, ChannelID: int, Command_Prefix="!"):
2525
self.token=str(Token)
2626
self.channelID=int(ChannelID)
2727

28+
self.debugLevel=DebugLevel
29+
self.imagePath=ImagePath
30+
2831
def SetCallbackStart(self, Func, *argv, **kwargs):
2932
"""Callback function called at start."""
3033
print("call back fbot")
@@ -58,18 +61,22 @@ async def on_ready(self):
5861
# pass
5962

6063
# Debug tests.
61-
if False:
64+
if self.debugLevel>=10:
6265
from funkman.utils.tests import testTrap, testBomb, testStrafe, getResultTrap
6366
from funkman.funkplot.funkplot import FunkPlot
6467

68+
print("Testing Plots...")
69+
6570
# Init FunkPlot.
6671
funkyplot=FunkPlot()
6772

6873
# Trap sheet file.
69-
trapfile="D:/Users/frank/Saved Games/DCS.openbeta/AIRBOSS-CVN-74_Trapsheet-New callsign_FA-18C_hornet-0001.csv"
74+
trapfile="./testfiles/Trapsheet-FA-18C_hornet-001.csv"
7075

71-
# Test LSO embed.
76+
# Get result from trap file.
7277
result=getResultTrap(trapfile)
78+
79+
# Test LSO embed.
7380
self.SendLSOEmbed(result, self.channelID)
7481

7582
# Test trap.
@@ -93,7 +100,7 @@ def Start(self, Threaded=False):
93100
discordThread=threading.Thread(target=self.Start, args=(False, ))
94101
discordThread.start()
95102
else:
96-
print(f"Starting Bot Client with Token {self.token}")
103+
print(f"Starting Bot Client with Token {self.token[0:5]}...")
97104
self.run(self.token)
98105

99106
async def SendMessage(self, Text: str, ChannelID: int):
@@ -207,7 +214,7 @@ def SendLSOEmbed(self, result, ChannelID: int):
207214
embed = discord.Embed(title="LSO Grade", description=f"Result for {player} at carrier {carriername} [{carriertype}]", color=color)
208215

209216
# Create file.
210-
fileLSO = discord.File("./images/LSO.png", filename="lso.png")
217+
fileLSO = discord.File(self.imagePath+"LSO.png", filename="lso.png")
211218

212219
# Images.
213220
embed.set_image(url="attachment://lso.png")

funkman/funkman.py

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FunkMan():
2525
def __init__(self, ConfigFile="./FunkMan.ini") -> None:
2626

2727
# Set config file.
28-
self.ConfigFile=ConfigFile
28+
self.configFile=ConfigFile
2929

3030
# Define parameters used later on.
3131
self.port=None
@@ -36,14 +36,17 @@ def __init__(self, ConfigFile="./FunkMan.ini") -> None:
3636
self.channelIDairboss=None
3737
self.imagePath=None
3838

39+
# Default debug level.
40+
self.debugLevel=0
41+
3942
# Read config file.
4043
_ReadConfig(self)
4144

4245
# Create funkplot instance.
4346
self.funkplot=FunkPlot(self.imagePath)
4447

4548
# Create funkbot instance.
46-
self.funkbot=FunkBot(self.token, self.channelIDmain)
49+
self.funkbot=FunkBot(self.token, self.channelIDmain, ImagePath=self.imagePath, DebugLevel=self.debugLevel)
4750

4851
# Create funksocket instance.
4952
self.funksock=FunkSocket(Host=self.host, Port=self.port)
@@ -83,46 +86,65 @@ def _ReadConfig(funkman: FunkMan) -> None:
8386
Reads the config file.
8487
"""
8588

86-
# Get the current working directory
87-
cwd = os.getcwd()
88-
89-
# Print the current working directory
90-
print("Current working directory: {0}".format(cwd))
89+
# Info message.
90+
print(f"Reading config file {funkman.configFile}")
9191

9292
# Check if config file exists
9393
try:
94-
os.path.exists(funkman.ConfigFile)
94+
os.path.exists(funkman.configFile)
9595
except FileNotFoundError:
96-
print(f"Could not find ini file {funkman.ConfigFile} in {cwd}!")
96+
print(f"Could not find ini file {funkman.configFile} in {os.getcwd()}!")
9797
quit()
9898

9999
# Config parser.
100100
config = configparser.ConfigParser()
101101

102102
# Read config file.
103-
config.read(funkman.ConfigFile)
103+
config.read(funkman.configFile)
104104

105-
# Section name of config.
106-
SectionName="FUNKMAN"
105+
# FUNKMAN
106+
try:
107+
section=config["DEFAULT"]
108+
funkman.debugLevel=section.getint("DEBUGLEVEL", 0)
109+
except:
110+
pass
107111

108-
# Get config parameters:
109-
funkman.port=int(config[SectionName]['PORT'])
110-
funkman.host=str(config[SectionName]['HOST'])
111-
funkman.token=config[SectionName]['TOKEN']
112-
funkman.channelIDmain=int(config[SectionName]['CHANNELID_MAIN'])
113-
funkman.channelIDrange=int(config[SectionName]['CHANNELID_RANGE'])
114-
funkman.channelIDairboss=int(config[SectionName]['CHANNELID_AIRBOSS'])
115-
funkman.imagePath=str(config[SectionName]['IMAGEPATH'])
112+
# FUNKBOT
113+
try:
114+
section=config["FUNKBOT"]
115+
funkman.token=section.get("TOKEN", "FROM_OS_ENV")
116+
funkman.channelIDmain=section.getint("CHANNELID_MAIN", 123456789)
117+
funkman.channelIDrange=section.getint("CHANNELID_RANGE", funkman.channelIDmain)
118+
funkman.channelIDairboss=section.getint("CHANNELID_AIRBOSS", funkman.channelIDmain)
119+
except:
120+
print("ERROR: [FUNKBOT] section missing in ini file!")
121+
122+
# FUNKSOCK
123+
try:
124+
section=config["FUNKSOCK"]
125+
funkman.port=section.getint("PORT", 10042)
126+
funkman.host=section.get("HOST", "127.0.0.1")
127+
except:
128+
print("ERROR: [FUNKSOCK] section missing in ini file!")
129+
130+
# FUNKPLOT
131+
try:
132+
section=config["FUNKPLOT"]
133+
funkman.imagePath=section.get("IMAGEPATH", "./funkpics/")
134+
except:
135+
print("ERROR: [FUNKPLOT] section missing in ini file!")
116136

117137
# Debug message.
118-
text =str(f"------------------------------------")
119-
text+=str(f"\nReading config file:")
120-
text+=str(f"\nHost = {funkman.host}")
121-
text+=str(f"\nPort = {funkman.port}")
122-
text+=str(f"\nToken = {funkman.token}")
123-
text+=str(f"\nChannel Main = {funkman.channelIDmain}")
124-
text+=str(f"\nChannel Range = {funkman.channelIDrange}")
125-
text+=str(f"\nChannel Airboss = {funkman.channelIDairboss}")
126-
text+=str(f"\nImage Path = {funkman.imagePath}")
127-
text+=str(f"\n------------------------------------")
128-
print(text)
138+
if funkman.debugLevel>0:
139+
text =str(f"------------------------------------")
140+
text+=str(f"\nConfig parameters:")
141+
text+=str(f"\nDebug level = {funkman.debugLevel}")
142+
text+=str(f"\nHost = {funkman.host}")
143+
text+=str(f"\nPort = {funkman.port}")
144+
text+=str(f"\nToken (5 chars) = {funkman.token[0:4]}...")
145+
text+=str(f"\nChannel Main = {funkman.channelIDmain}")
146+
text+=str(f"\nChannel Range = {funkman.channelIDrange}")
147+
text+=str(f"\nChannel Airboss = {funkman.channelIDairboss}")
148+
text+=str(f"\nImage Path = {funkman.imagePath}")
149+
text+=str(f"\n------------------------------------")
150+
print(text)

funkman/funkplot/funkplot.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,28 @@ def getAoA(self):
4848

4949
class FunkPlot():
5050

51-
def __init__(self, ImagePath="./images/") -> None:
51+
def __init__(self, ImagePath="./funkpics/") -> None:
5252

5353
# Info message.
54-
print("Init FunkPlot: Reading images...")
54+
print(f"Init FunkPlot: Reading images from {ImagePath}...")
5555

56-
path=ImagePath
56+
# Append / if necessary.
57+
if not ImagePath.endswith("/") or ImagePath.endswith("\\"):
58+
ImagePath=ImagePath+"/"
5759

5860
# Read images:
59-
self.imageBombCircle = plt.imread(path+"BombCircle.png")
60-
self.imageStrafePit = plt.imread(path+"StrafePit.png")
61+
self.imageBombCircle = plt.imread(ImagePath+"BombCircle.png")
62+
self.imageStrafePit = plt.imread(ImagePath+"StrafePit.png")
6163

62-
self.imageCVNside = plt.imread(path+'CarrierCVN_Side.png')
63-
self.imageCVNtop = plt.imread(path+'CarrierCVN_TopDown.png')
64+
self.imageCVNside = plt.imread(ImagePath+'CarrierCVN_Side.png')
65+
self.imageCVNtop = plt.imread(ImagePath+'CarrierCVN_TopDown.png')
6466

65-
self.imageLHAside = plt.imread(path+'CarrierLHA_Side.png')
66-
self.imageLHAtop = plt.imread(path+'CarrierLHA_Side.png')
67+
self.imageLHAside = plt.imread(ImagePath+'CarrierLHA_Side.png')
68+
self.imageLHAtop = plt.imread(ImagePath+'CarrierLHA_Side.png')
6769

68-
self.imageCrater = plt.imread(path+"Crater.png")
69-
self.imageNorthUp = plt.imread(path+"NorthUp.png")
70-
self.imageBullet = plt.imread(path+"BulletHole.png")
70+
self.imageCrater = plt.imread(ImagePath+"Crater.png")
71+
self.imageNorthUp = plt.imread(ImagePath+"NorthUp.png")
72+
self.imageBullet = plt.imread(ImagePath+"BulletHole.png")
7173

7274

7375
def _GetAoA(self, actype: str):
@@ -600,8 +602,4 @@ def PlotTrapSheet(self, result):
600602
# Show plot.
601603
#plt.show()
602604

603-
return fig, axs
604-
605-
606-
607-
605+
return fig, axs

funkman/utils/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def getResultTrap(trapfile: str):
5757
# Read trapsheet from disk for testing.
5858
trapsheet=ReadTrapsheet(trapfile)
5959

60+
# Debug info.
61+
#print(trapsheet)
62+
6063
# Result.
6164
result={
6265
"dataType": "Trap Sheet",

0 commit comments

Comments
 (0)