-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongomethods.py
More file actions
222 lines (168 loc) · 5.48 KB
/
mongomethods.py
File metadata and controls
222 lines (168 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import motor.motor_asyncio
import pymongo
import discord
import dns
import os
client1 = motor.motor_asyncio.AsyncIOMotorClient(os.environ["MONGO"])
db1 = client1.db_name
my_collection = db1.collection_name
async def find_lb():
data = my_collection.find({}).sort("data.prestige", -1)
data = await data.to_list(10)
return data
async def find_lb2():
data = my_collection.find({}).sort("data.coins", -1)
data = await data.to_list(10)
return data
async def delete_task(user_id):
await my_collection.delete_one({"_id": str(user_id)})
async def find_inventory(user_id, ctx=None):
inventory = await my_collection.find_one({"_id": str(user_id)})
if inventory is None:
if ctx is None:
raise Exception
prefix = ctx.prefix
embed = discord.Embed(
title="Hey!",
description=f"You do not have a country! Type `{prefix}start` to start your country!",
)
await ctx.send(embed=embed)
else:
inventory = dict(inventory)
return inventory["inventory"]
async def writing(arg):
await my_collection.insert_one(
{
"_id": str(arg[0]),
"data": {
"name": arg[1],
"population": arg[2],
"multiplier": arg[3],
"job": arg[4],
"work_ethic": arg[5],
"prestige": arg[6],
"requirement": arg[7],
"wars_played": arg[8],
"wars_won": arg[9],
"wars_lost": arg[10],
"times_worked": arg[11],
"coins": arg[12],
},
"inventory": {},
}
)
async def reading(user_id, ctx=None):
data = await my_collection.find_one({"_id": str(user_id)})
if not data:
if not ctx:
raise KeyError("User does not have a country -__-")
try:
prefix = ctx.prefix
embed = discord.Embed(
title="Hey!",
description=f"You do not have a country! Type `{prefix}start` to start your country!",
)
await ctx.send(embed=embed)
except AttributeError:
embed = discord.Embed(
title="Hey!",
description=f"You do not have a country! Type `/start` to start your country!",
)
await ctx.send(embed=embed)
elif data:
data = dict(data)
data = data["data"]
return [list(data.values())]
async def update_war(arg):
await my_collection.update_one(
{"_id": str(arg[0])},
{
"$set": {
"data.name": arg[1],
"data.population": arg[2],
"data.multiplier": arg[3],
"data.job": arg[4],
"data.work_ethic": arg[5],
"data.wars_played": arg[8],
"data.wars_won": arg[9],
"data.wars_lost": arg[10],
}
},
)
async def update_prestige(arg):
await my_collection.update_one(
{"_id": str(arg[0])},
{
"$set": {
"data.name": arg[1],
"data.population": arg[2],
"data.multiplier": arg[3],
"data.job": arg[4],
"data.work_ethic": arg[5],
"data.prestige": arg[6],
"data.requirement": arg[7],
}
},
)
async def update(arg):
await my_collection.update_one(
{"_id": str(arg[0])},
{
"$set": {
"data.name": arg[1],
"data.population": arg[2],
"data.multiplier": arg[3],
"data.job": arg[4],
"data.work_ethic": arg[5],
"data.times_worked": arg[6],
}
},
)
async def count():
doccount = await my_collection.count_documents({})
return doccount
async def update_coins(arg):
await my_collection.update_one(
{"_id": str(arg[0])}, {"$set": {"data.coins": arg[1]}}
)
async def update_inventory(arg):
await my_collection.update_one(
{"_id": str(arg[0])}, {"$set": {"inventory": arg[1]}}
)
async def search_name(name):
data = await my_collection.find_one({"data.name": name})
data = [list(data["data"].values())]
return data
db2 = client1.bot_updates
my_collection2 = db2.update_info
async def create_update(channel):
data = await my_collection2.find_one({"_id": int(channel)})
if data is None:
pass
else:
raise Exception
await my_collection2.insert_one({"_id": int(channel)})
def findall():
data = my_collection2.find({})
return data
async def delete_update(channel):
data = await my_collection2.find_one({"_id": int(channel)})
if data is not None:
pass
else:
raise Exception
await my_collection2.delete_one({"_id": int(channel)})
prefixes_db = client1.prefixes.main
async def create_prefix(id, prefix):
await prefixes_db.insert_one({"_id": str(id), "prefix": prefix})
async def update_prefix(id, prefix):
await prefixes_db.update_one({"_id": str(id)}, {"$set": {"prefix": prefix}})
async def delete_prefix(id):
await prefixes_db.delete_one({"_id": str(id)})
client3 = pymongo.MongoClient(os.getenv("MONGO"))
prefixes_db2 = client3.prefixes.main
def create_prefix2(id, prefix):
prefixes_db2.insert_one({"_id": str(id), "prefix": prefix})
def get_prefix2(id):
prefix = prefixes_db2.find_one({"_id": str(id)})
return prefix["prefix"]